3段階の追加問題終わりました

This commit is contained in:
2026-09-14 16:41:41 +09:00
parent 47cfdcf026
commit 4ef8fca04f
2 changed files with 10 additions and 1 deletions

View File

@@ -21,8 +21,11 @@ public class BasicCheck3 {
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
items[i].sell(5); items[i].sell(5);
System.out.println(items[i].name + " " + items[i].price + "円 残り" + items[i].stock + "個 "); System.out.println(items[i].name + " " + items[i].price + "円 残り" + items[i].stock + "個 ");
System.out.println("合計金額 " + items[i].totalPrice() + "円");
System.out.println();
} }
} }
} }

View File

@@ -6,5 +6,11 @@ public class Item {
public void sell(int amount) { public void sell(int amount) {
this.stock = this.stock - amount; this.stock = this.stock - amount;
} }
public int totalPrice() {
return price * stock;
}
} }