-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
48 lines (33 loc) · 889 Bytes
/
Rectangle.java
File metadata and controls
48 lines (33 loc) · 889 Bytes
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
// subclass of polygon
public class Rectangle extends Polygon {
private double length;
private double width;
public Rectangle(double length, double width) {
super(4);
this.length = length;
this.width = width;
}
@Override
public String getName() {
return "Rectangle";
}
@Override
public double getArea() {
return length * width;
}
@Override
public double getPerimeter() {
return 2 * (length + width);
}
@Override
public String toString() {
return String.format(
"Rectangle: Length: %.2f, Width: %.2f, Sides: %d, Perimeter: %.2f, Area: %.2f]",
length,
width,
getSides(),
getPerimeter(),
getArea()
);
}
}