From 769fb977ca681829dd54886cf3001da72975d78f Mon Sep 17 00:00:00 2001 From: s-sakiyama <26-m-s-stella-tecnica@it-college.jp> Date: Mon, 14 Sep 2026 16:32:27 +0900 Subject: [PATCH] =?UTF-8?q?3=E6=AE=B5=E9=9A=8E=E7=9B=AE=EF=BC=88=E8=A4=87?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=82=92=E6=89=B1=E3=81=A3=E3=81=A6=E3=81=BF=E3=82=88?= =?UTF-8?q?=E3=81=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- em-oop/src/BasicCheck3.java | 26 ++++++++++++++++++++++++++ em-oop/src/Item.java | 14 ++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 em-oop/src/BasicCheck3.java create mode 100644 em-oop/src/Item.java diff --git a/em-oop/src/BasicCheck3.java b/em-oop/src/BasicCheck3.java new file mode 100644 index 0000000..3c31234 --- /dev/null +++ b/em-oop/src/BasicCheck3.java @@ -0,0 +1,26 @@ + +public class BasicCheck3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Item[] items = new Item[3]; + for (int i = 0; i < items.length; i++) { + items[i] = new Item(); + } + items[0].name = "ノート"; + items[0].price = 120; + items[0].stock = 50; + items[1].name = "消しゴム"; + items[1].price = 80; + items[1].stock = 30; + items[2].name = "鉛筆"; + items[2].price = 60; + items[2].stock = 100; + + for (Item i : items) { + i.sell(5); + System.out.println(i.name + " " + i.price + "円 残り" + i.stock + "個 合計金額" + i.totalPrice() + "円"); + } + } + +} diff --git a/em-oop/src/Item.java b/em-oop/src/Item.java new file mode 100644 index 0000000..a379897 --- /dev/null +++ b/em-oop/src/Item.java @@ -0,0 +1,14 @@ + +public class Item { + String name; + int price; + int stock; + + void sell(int amount) { + this.stock -= amount; + } + + int totalPrice() { + return this.price * this.stock; + } +} \ No newline at end of file