-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCircle.java
More file actions
50 lines (40 loc) · 1.16 KB
/
Circle.java
File metadata and controls
50 lines (40 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package src.ex4;
public class Circle extends Shape {
protected double radius;
public Circle() {
super();
radius = 1.0;
}
public Circle(double radius) {
super();
this.radius = radius;
}
public Circle(double radius, String color, boolean filled) {
super(color, filled);
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
@Override
public double getArea() {
return radius*radius*Math.PI;
}
@Override
public double getPerimeter() {
return 2 * radius * Math.PI;
}
@Override
public String toString() {
// StringBuilder sb = new StringBuilder();
// Formatter formatter = new java.util.Formatter(sb);
// formatter.format("A Circle with radius = %d, which is a subclass of %s"
// , radius, super.toString());
// return sb.toString();
return String.format("A Circle with radius = %f, which is a subclass of %s"
, radius, super.toString());
}
}