3日目段階1です
This commit is contained in:
22
em-oop/src/Circle.java
Normal file
22
em-oop/src/Circle.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
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/DayCheck1.java
Normal file
9
em-oop/src/DayCheck1.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
public class DayCheck1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Circle radius = new Circle(2);
|
||||||
|
|
||||||
|
radius.showInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
em-oop/src/Shape.java
Normal file
17
em-oop/src/Shape.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
public class Shape {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Shape(String name) {
|
||||||
|
|
||||||
|
this.name =name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double area() {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showInfo() {
|
||||||
|
System.out.println(this.name + "の面積は" + this.area() + "です");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user