diff --git a/em-oop/src/Circle.java b/em-oop/src/Circle.java new file mode 100644 index 0000000..b000e95 --- /dev/null +++ b/em-oop/src/Circle.java @@ -0,0 +1,20 @@ + +public class Circle extends Shape { + private double radius; + + public Circle(double radius) { + super("円"); + this.radius = radius; + } + + @Override + public double area() { + return Math.PI * radius * radius; + } + + @Override + public void showInfo() { + super.showInfo(); + System.out.println("(半径:" + this.radius + ")"); + } +} diff --git a/em-oop/src/Day3Check1.java b/em-oop/src/Day3Check1.java new file mode 100644 index 0000000..ffa0cdb --- /dev/null +++ b/em-oop/src/Day3Check1.java @@ -0,0 +1,9 @@ + +public class Day3Check1 { + + public static void main(String[] args) { + Circle circle = new Circle(2); + circle.showInfo(); + } + +} diff --git a/em-oop/src/Day3Check2.java b/em-oop/src/Day3Check2.java new file mode 100644 index 0000000..eca32b3 --- /dev/null +++ b/em-oop/src/Day3Check2.java @@ -0,0 +1,11 @@ + +public class Day3Check2 { + public static void main(String[] args) { + Rectangle rectangle = new Rectangle(3, 4); + rectangle.showInfo(); + + Greeting greeting = new JapaneseGreeting(); + System.out.println(greeting.hello()); + } + +} diff --git a/em-oop/src/DayCheck3.java b/em-oop/src/DayCheck3.java new file mode 100644 index 0000000..5048744 --- /dev/null +++ b/em-oop/src/DayCheck3.java @@ -0,0 +1,12 @@ + +public class DayCheck3 { + + public static void main(String[] args) { + Shape shape1 = new Circle(2); + shape1.showInfo(); + + Shape shape2 = new Rectangle(3, 4); + shape2.showInfo(); + } + +} diff --git a/em-oop/src/Greeting.java b/em-oop/src/Greeting.java new file mode 100644 index 0000000..eb48467 --- /dev/null +++ b/em-oop/src/Greeting.java @@ -0,0 +1,3 @@ +public interface Greeting { + String hello(); +} \ No newline at end of file diff --git a/em-oop/src/JapaneseGreeting.java b/em-oop/src/JapaneseGreeting.java new file mode 100644 index 0000000..dda3121 --- /dev/null +++ b/em-oop/src/JapaneseGreeting.java @@ -0,0 +1,7 @@ + +public class JapaneseGreeting implements Greeting { + @Override + public String hello() { + return "こんにちは"; + } +} diff --git a/em-oop/src/Rectangle.java b/em-oop/src/Rectangle.java new file mode 100644 index 0000000..fc40e25 --- /dev/null +++ b/em-oop/src/Rectangle.java @@ -0,0 +1,16 @@ + +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; + } +} diff --git a/em-oop/src/Shape.java b/em-oop/src/Shape.java new file mode 100644 index 0000000..3d099c9 --- /dev/null +++ b/em-oop/src/Shape.java @@ -0,0 +1,14 @@ + +public abstract class Shape { + private String name; + + public Shape(String name) { + this.name = name; + } + + public abstract double area(); + + public void showInfo() { + System.out.println(this.name + "の面積は" + this.area() + "です"); + } +}