forked from HarryDulaney/intro-to-java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRectangle.java
55 lines (39 loc) · 1 KB
/
Rectangle.java
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
package ch_13.exercise13_12;
public class Rectangle extends GeometricObject {
private double width;
private double height;
public Rectangle() {
width = 1;
height = 1;
}
public Rectangle(double newWidth, double newHeight) {
width = newWidth;
height = newHeight;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
@Override
public double getArea() {
double area = width * height;
return area;
}
@Override
public double getPerimeter() {
return (2 * width) + (2 * height);
}
@Override
public String toString() {
return super.toString() + "\nWidth: " + width + "\nHeight: " + height
+ "\nArea: " + getArea() + "\nPerimeter: " + getPerimeter();
}
}