-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathRectangle.java
More file actions
60 lines (48 loc) · 1.45 KB
/
Rectangle.java
File metadata and controls
60 lines (48 loc) · 1.45 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
51
52
53
54
55
56
57
58
59
60
package src.ex4;
public class Rectangle extends Shape {
protected double width;
protected double length;
public Rectangle() {
super();
width = 1.0;
length = 1.0;
}
public Rectangle(double width, double length) {
super();
this.width = width;
this.length = length;
}
public Rectangle(double width, double length, String color, boolean filled) {
super(color, filled);
this.width = width;
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getArea() {
return width * length;
}
public double getPerimeter() {
return 2 * (width+length);
}
@Override
public String toString() {
// StringBuilder sb = new StringBuilder();
// Formatter formatter = new java.util.Formatter(sb);
// formatter.format("A Rectangle with width = %d and length = %d, which is a subclass of %s"
// , width, length, super.toString());
// return sb.toString();
return String.format("A Rectangle with width = %f and length = %f, which is a subclass of %s"
, width, length, super.toString());
}
}