diff --git a/em-oop/src/BasicCheck3.java b/em-oop/src/BasicCheck3.java index 80c2b54..70e0985 100644 --- a/em-oop/src/BasicCheck3.java +++ b/em-oop/src/BasicCheck3.java @@ -23,6 +23,11 @@ public class BasicCheck3 { items[2].stock = 100; + + + + + for(int i = 0; i <= 2; i++ ) { items[i].sell(5); diff --git a/em-oop/src/Circle.java b/em-oop/src/Circle.java new file mode 100644 index 0000000..b949cb9 --- /dev/null +++ b/em-oop/src/Circle.java @@ -0,0 +1,21 @@ + +public class Circle extends Shape { //shapeクラスを継承する + private double radius; { //radius: 半径 フィールドradius (double型、private) + + } + + public Circle(double radius) { //コンストラクタpub 引数dou/raを受け取る + super("円"); //"円"呼び出し 文字列 + this.radius = radius; //radiusフィールドにも引数の値を代入する。 + + } + public double area() { //Overrideは 子クラスで! + return Math.PI * radius * radius; + } + public void showInfo(){ + super.showInfo(); + System.out.println("(半径:" + this.radius + ")"); + } + + +} diff --git a/em-oop/src/Day3Check1.java b/em-oop/src/Day3Check1.java new file mode 100644 index 0000000..253263b --- /dev/null +++ b/em-oop/src/Day3Check1.java @@ -0,0 +1,11 @@ + +public class Day3Check1 { + + public static void main(String[] args) { + + Circle circle = new Circle(2); + circle.area(); + circle.showInfo(); + + } +} diff --git a/em-oop/src/Item.java b/em-oop/src/Item.java index a31aca4..d710c22 100644 --- a/em-oop/src/Item.java +++ b/em-oop/src/Item.java @@ -1,9 +1,31 @@ public class Item { //フィールドを宣言 - String name; - int price; - int stock; + private String name; + private int price; + private int stock; + + public String getName() { + return this.name; + } + public void setName(String name) { + this.name = name; + } + + public int getPrice() { + return this.price; + } + public void getPrice(String name) { + this.price = price; + } + + public int getStock() { + return this.stock; + } + public void setStock() { + this.stock = stock; + } + // Item(String name, int price, int stock){ // this.name = name; @@ -15,7 +37,7 @@ public class Item { //メソッドを宣言 //stockからamountを引く - this.stock = this.stock - amount; + this.getStock(this.getStock() - amount); } } diff --git a/em-oop/src/Shape.java b/em-oop/src/Shape.java new file mode 100644 index 0000000..790e1bd --- /dev/null +++ b/em-oop/src/Shape.java @@ -0,0 +1,34 @@ + +public class Shape { + + private String name; //フィールドname ・privateにしなきゃいけない + public double area; + public int radius; + + public Shape() { + } + + public Shape(String name) { + this.name = name; //Circleが"円"を呼び出すための文字列をいれるところ + } + + public double area() { //メソッドarea 引数なし・戻り値double 中身return0.0; + return 0.0; + } + +// @Override + + + public void showInfo(){ //メソッドshowinfo 引数戻り値なし・中身はsyso + System.out.println(this.name + "の面積は" + this.area() + "です"); + System.out.println("(半径:" + this.radius + ")"); + } + +// @Override +// public void showInfo(){ +// +// } + + + +}