From f1c2d91ae70faa2003855fb244b9dd3196285946 Mon Sep 17 00:00:00 2001 From: o-matsuda <26-o-matsuda-stellatecnica@it-college.co.jp> Date: Mon, 14 Sep 2026 16:07:43 +0900 Subject: [PATCH] =?UTF-8?q?=E6=AE=B5=E9=9A=8E=EF=BC=93=E5=AE=8C=E4=BA=86?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- em-oop/src/BasicCheck3.java | 28 ++++++++++++++++++++++++++++ em-oop/src/Item.java | 9 +++++++++ 2 files changed, 37 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..68e3d08 --- /dev/null +++ b/em-oop/src/BasicCheck3.java @@ -0,0 +1,28 @@ + +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]代入 + items[0].name = "ノート"; + items[0].price = 120; + items[0].stock = 50; + //items[1]代入 + items[1].name = "消しゴム"; + items[1].price = 80; + items[1].stock = 30; + //items[2]代入 + items[2].name = "鉛筆"; + items[2].price = 60; + items[2].stock = 100; + for (int i=0; i<=2; i++) { + items[i].sell(5); + System.out.println(items[i].name + items[i].price+"円"+ "残り"+ items[i].stock + "個"); + } + + } +} \ No newline at end of file diff --git a/em-oop/src/Item.java b/em-oop/src/Item.java new file mode 100644 index 0000000..6d37e90 --- /dev/null +++ b/em-oop/src/Item.java @@ -0,0 +1,9 @@ + +public class Item { + String name; + int price; + int stock; + void sell(int amount) { + this.stock = this.stock - amount; + } +}