3日目_1段階

This commit is contained in:
2026-09-16 15:59:09 +09:00
parent f4acecff05
commit 012cbcd562
5 changed files with 97 additions and 4 deletions

View File

@@ -23,6 +23,11 @@ public class BasicCheck3 {
items[2].stock = 100; items[2].stock = 100;
for(int i = 0; i <= 2; i++ ) for(int i = 0; i <= 2; i++ )
{ {
items[i].sell(5); items[i].sell(5);

21
em-oop/src/Circle.java Normal file
View 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 + ")");
}
}

View File

@@ -0,0 +1,11 @@
public class Day3Check1 {
public static void main(String[] args) {
Circle circle = new Circle(2);
circle.area();
circle.showInfo();
}
}

View File

@@ -1,9 +1,31 @@
public class Item { public class Item {
//フィールドを宣言 //フィールドを宣言
String name; private String name;
int price; private int price;
int stock; 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){ // Item(String name, int price, int stock){
// this.name = name; // this.name = name;
@@ -15,7 +37,7 @@ public class Item {
//メソッドを宣言 //メソッドを宣言
//stockからamountを引く //stockからamountを引く
this.stock = this.stock - amount; this.getStock(this.getStock() - amount);
} }
} }

34
em-oop/src/Shape.java Normal file
View 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(){
//
// }
}