-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangleShape.java
More file actions
50 lines (41 loc) · 1.01 KB
/
RectangleShape.java
File metadata and controls
50 lines (41 loc) · 1.01 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 unit_07.Examples.Example_08;
public class RectangleShape {
protected double length, width;
public RectangleShape() {
length = 0;
width = 0;
}
public RectangleShape(double length, double width) {
setDiemnsion(length, width);
}
public void setDiemnsion(double length, double width) {
if (length >= 0) {
this.length = length;
} else {
this.length = 0;
}
if (width >= 0) {
this.width = width;
} else {
width = 0;
}
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
public double area() {
return (length * width);
}
public double perimeter() {
return 2 * (length * width);
}
public String toString() {
return ("Length: " + length
+ " Width: " + width
+ " Area: " + area()
+ " Perimeter: " + perimeter());
}
}