-2

現在、私は持っています

public void sellAllBut() {
Iterator<String> i = inventory.iterator();
while (i.hasNext()) {
  if (!i.next().equalsIgnoreCase("pickaxe")) {
    i.remove();
  }   
}

}

現在、inventory.class 文字列配列からアイテムを削除するだけです。そのアイテムを削除するときに、inventory.goldCoins += intvalue; を使用して金の量を追加するように追加するにはどうすればよいですか?

私のint値は

    //ores
    int copperoPrice = 150;
    int ironoPrice = 200;
    int steeloPrice = 350;
    int goldoPrice = 500;
    int diamondoPrice = 700;
    int pickaxePrice = 500;

配列に入れられる項目は次のとおりです。

    String ore = null;


     if (oreFind <= 50) {
         ore = "Copper ore";

         } 

     if (oreFind >=51) {
         if (oreFind <= 70) {
             ore = "Iron ore";
         }
     }
     if (oreFind >=71) {
         if (oreFind <= 90) {
             ore = "Steel ore";
         }
     }
     if (oreFind >=91) {
         if (oreFind <= 99) {
             ore = "Gold ore";
         }
     }
     if (oreFind == 100) { 
             ore = "Diamond ore";
     }

文字列値が鉱石に設定された後、次のコード行を使用してインベントリ文字列配列に追加します。

inventory.addInventory(鉱石);

たとえば、私の在庫には [ダイヤモンド鉱石、金鉱石、金鉱石] があります。

これらのそれぞれに価格を付けて、sellAllBut ボイドに入れるにはどうすればよいですか?

4

1 に答える 1