2段階目終わりました
This commit is contained in:
11
em-oop/src/Day3Check2.java
Normal file
11
em-oop/src/Day3Check2.java
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
public class Day3Check2 {
|
||||
public static void main(String[] args) {
|
||||
Rectangle rect = new Rectangle(3, 4);
|
||||
rect.showInfo();
|
||||
|
||||
Greeting greeting = new JapaneseGreeting();
|
||||
System.out.println(greeting.hello());
|
||||
}
|
||||
|
||||
}
|
||||
6
em-oop/src/Greeting.java
Normal file
6
em-oop/src/Greeting.java
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
public interface Greeting {
|
||||
|
||||
String hello();
|
||||
|
||||
}
|
||||
8
em-oop/src/JapaneseGreeting.java
Normal file
8
em-oop/src/JapaneseGreeting.java
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
public class JapaneseGreeting implements Greeting {
|
||||
@Override
|
||||
public String hello() {
|
||||
return "こんにちは";
|
||||
}
|
||||
|
||||
}
|
||||
17
em-oop/src/Rectangle.java
Normal file
17
em-oop/src/Rectangle.java
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
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() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
|
||||
public class Shape {
|
||||
public abstract class Shape {
|
||||
private String name;
|
||||
|
||||
public Shape(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double area() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public abstract double area();
|
||||
|
||||
public void showInfo() {
|
||||
System.out.println(this.name + "の面積は" + this.area() + "です");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user