From 1b2d0829d126c054c02120f401740103cfb9b92d Mon Sep 17 00:00:00 2001 From: m_ozawa <26-m-ozawa-swnet@it-college.co.jp> Date: Mon, 14 Sep 2026 16:07:03 +0900 Subject: [PATCH] =?UTF-8?q?0914=20=E6=AE=B5=E9=9A=8E=EF=BC=93=E3=80=80?= =?UTF-8?q?=E5=B0=8F=E6=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- em-oop/src/BasicCheck3.java | 35 +++++++++++++++++++++++++++++++++++ em-oop/src/Item.java | 11 +++++++++++ 2 files changed, 46 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..d12e219 --- /dev/null +++ b/em-oop/src/BasicCheck3.java @@ -0,0 +1,35 @@ + +public class BasicCheck3 { + public static void main(String[] args) { + Item[] items = new Item[3]; + items[0] = new Item(); + items[1] = new Item(); + items[2] = 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(int i=0;i<3;i++) { + items[i].sell(5); + System.out.println(items[i].name+" "+items[i].price+"円 残り"+items[i].stock+"個"); + + + + + } + } + + + +} diff --git a/em-oop/src/Item.java b/em-oop/src/Item.java new file mode 100644 index 0000000..311d0b6 --- /dev/null +++ b/em-oop/src/Item.java @@ -0,0 +1,11 @@ + +public class Item { + String name; + int price; + int stock; + + public void sell(int amount) { + this.stock = this.stock - amount; + } + +}