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; + } + +}