From 4ef8fca04fb7e319782184efa8951a262c9139bc Mon Sep 17 00:00:00 2001 From: t-eguchi <26-t-eguchi-tmn@it-college.co.jp> Date: Mon, 14 Sep 2026 16:41:41 +0900 Subject: [PATCH] =?UTF-8?q?=EF=BC=93=E6=AE=B5=E9=9A=8E=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E5=95=8F=E9=A1=8C=E7=B5=82=E3=82=8F=E3=82=8A=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- em-oop/src/BasicCheck3.java | 5 ++++- em-oop/src/Item.java | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/em-oop/src/BasicCheck3.java b/em-oop/src/BasicCheck3.java index 9b617a5..f3af7a4 100644 --- a/em-oop/src/BasicCheck3.java +++ b/em-oop/src/BasicCheck3.java @@ -21,8 +21,11 @@ public class BasicCheck3 { for (int i = 0; i < items.length; i++) { items[i].sell(5); System.out.println(items[i].name + " " + items[i].price + "円 残り" + items[i].stock + "個 "); + System.out.println("合計金額 " + items[i].totalPrice() + "円"); + System.out.println(); + } - } + } } diff --git a/em-oop/src/Item.java b/em-oop/src/Item.java index f9b8a9f..e1361de 100644 --- a/em-oop/src/Item.java +++ b/em-oop/src/Item.java @@ -6,5 +6,11 @@ public class Item { public void sell(int amount) { this.stock = this.stock - amount; } + + public int totalPrice() { + return price * stock; + + } + }