9/16のミッション課題1~3です
This commit is contained in:
20
em-oop/src/Circle.java
Normal file
20
em-oop/src/Circle.java
Normal file
@@ -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 + ")");
|
||||
}
|
||||
}
|
||||
9
em-oop/src/Day3Check1.java
Normal file
9
em-oop/src/Day3Check1.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Day3Check1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Circle circle = new Circle(2);
|
||||
circle.showInfo();
|
||||
}
|
||||
|
||||
}
|
||||
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 rectangle = new Rectangle(3, 4);
|
||||
rectangle.showInfo();
|
||||
|
||||
Greeting greeting = new JapaneseGreeting();
|
||||
System.out.println(greeting.hello());
|
||||
}
|
||||
|
||||
}
|
||||
12
em-oop/src/DayCheck3.java
Normal file
12
em-oop/src/DayCheck3.java
Normal file
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
3
em-oop/src/Greeting.java
Normal file
3
em-oop/src/Greeting.java
Normal file
@@ -0,0 +1,3 @@
|
||||
public interface Greeting {
|
||||
String hello();
|
||||
}
|
||||
7
em-oop/src/JapaneseGreeting.java
Normal file
7
em-oop/src/JapaneseGreeting.java
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
public class JapaneseGreeting implements Greeting {
|
||||
@Override
|
||||
public String hello() {
|
||||
return "こんにちは";
|
||||
}
|
||||
}
|
||||
16
em-oop/src/Rectangle.java
Normal file
16
em-oop/src/Rectangle.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
14
em-oop/src/Shape.java
Normal file
14
em-oop/src/Shape.java
Normal file
@@ -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() + "です");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user