diff --git a/em-oop/src/day3Keisho/Day3Check2.java b/em-oop/src/day3Keisho/Day3Check2.java new file mode 100644 index 0000000..5b2d35e --- /dev/null +++ b/em-oop/src/day3Keisho/Day3Check2.java @@ -0,0 +1,15 @@ +package day3Keisho; + +public class Day3Check2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Rectangle rect = new Rectangle(3.0, 4.0); + rect.showInfo(); + + Greeting greeting = new JapaneseGreeting(); + + System.out.println(greeting.hello()); + + } +} \ No newline at end of file diff --git a/em-oop/src/day3Keisho/Greeting.java b/em-oop/src/day3Keisho/Greeting.java new file mode 100644 index 0000000..8ce0fcf --- /dev/null +++ b/em-oop/src/day3Keisho/Greeting.java @@ -0,0 +1,6 @@ +package day3Keisho; + +public interface Greeting { + String hello(); + +} diff --git a/em-oop/src/day3Keisho/JapaneseGreeting.java b/em-oop/src/day3Keisho/JapaneseGreeting.java new file mode 100644 index 0000000..74db6f0 --- /dev/null +++ b/em-oop/src/day3Keisho/JapaneseGreeting.java @@ -0,0 +1,11 @@ +package day3Keisho; + +public class JapaneseGreeting implements Greeting { + @Override + public String hello() { + return "こんにちは"; + } + + + +} diff --git a/em-oop/src/day3Keisho/Rectangle.java b/em-oop/src/day3Keisho/Rectangle.java new file mode 100644 index 0000000..e896375 --- /dev/null +++ b/em-oop/src/day3Keisho/Rectangle.java @@ -0,0 +1,21 @@ +package day3Keisho; + +public class Rectangle extends Shape { + private double width; + private double height; + + + public Rectangle(double width,double height) { + super("四角形"); + this.height=height; + this.width=width; + } + + @Override + public double area() { + // TODO 自動生成されたメソッド・スタブ + //super.showInfo(); + return width*height; + } + +} diff --git a/em-oop/src/day3Keisho/Shape.java b/em-oop/src/day3Keisho/Shape.java index ef93f46..0af00d0 100644 --- a/em-oop/src/day3Keisho/Shape.java +++ b/em-oop/src/day3Keisho/Shape.java @@ -1,16 +1,19 @@ package day3Keisho; -public class Shape { +//public class Shape { //stept 1 + + public abstract class Shape{ //stept 2 private String name; public Shape(String name) { this.name = name; } - public double area() { - return 0.0; - - } + public abstract double area(); //stept 2 +// public double area() { //stept 1 +// return 0.0; +// +// } public void showInfo() { System.out.println(this.name + "の面積は" + this.area() + "です");