-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
46 lines (37 loc) · 855 Bytes
/
Rectangle.java
File metadata and controls
46 lines (37 loc) · 855 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
package unit_07.Examples.Example_01;
public class Rectangle {
private double length, width;
public Rectangle() {
setDeimension(0.0, 0.0);
}
public Rectangle(double l, double w) {
setDeimension(l, w);
}
public void setDeimension(double l, double w) {
if (l >= 0) {
length = l;
} else {
length = 0;
}
if (w >= 0) {
width = w;
} 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 toStr() {
return ("Length = " + length + " , Width = " + width);
}
}