3日目_1段階
This commit is contained in:
@@ -23,6 +23,11 @@ public class BasicCheck3 {
|
||||
items[2].stock = 100;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i <= 2; i++ )
|
||||
{
|
||||
items[i].sell(5);
|
||||
|
||||
21
em-oop/src/Circle.java
Normal file
21
em-oop/src/Circle.java
Normal file
@@ -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 + ")");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
em-oop/src/Day3Check1.java
Normal file
11
em-oop/src/Day3Check1.java
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
public class Day3Check1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Circle circle = new Circle(2);
|
||||
circle.area();
|
||||
circle.showInfo();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
34
em-oop/src/Shape.java
Normal file
34
em-oop/src/Shape.java
Normal file
@@ -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(){
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user