2段階目

This commit is contained in:
m-shimizu
2026-09-16 16:47:52 +09:00
parent 86a51ddb8e
commit ba035d4a3c
5 changed files with 51 additions and 5 deletions

View File

@@ -0,0 +1,14 @@
public class Day3Check2 {
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(3,4);
rectangle.showInfo();
System.out.println("四角形の面積は" + rectangle.area() + "です");
Greeting greeting = new JapaneseGreeting();
System.out.println(greeting.hello());
}
}

3
em-oop/src/Greeting.java Normal file
View File

@@ -0,0 +1,3 @@
public interface Greeting {
String hello();
}

View File

@@ -0,0 +1,9 @@
public class JapaneseGreeting implements Greeting {
@Override
public String hello() {
return "こんにちは";
}
}

20
em-oop/src/Rectangle.java Normal file
View File

@@ -0,0 +1,20 @@
public class Rectangle extends Shape {
private double width;
private double height;
public Rectangle(double width, double height) {
super("四角");
this.width = width;
this.height = height;
}
@Override
public double area() {
// TODO 自動生成されたメソッド・スタブ
return width * height;
}
}

View File

@@ -1,5 +1,5 @@
public class Shape { public abstract class Shape {
private String name; private String name;
@@ -8,13 +8,13 @@ public class Shape {
} }
public double area() { public abstract double area();
return 0.0; //return 0.0;
}
public void showInfo() { public void showInfo() {
System.out.println(this.name + "の面積は" + this.area() + "です"); //System.out.println(this.name + "の面積は" + this.area() + "です");
} }
} }