-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangleFigure.java
More file actions
51 lines (41 loc) · 1.02 KB
/
RectangleFigure.java
File metadata and controls
51 lines (41 loc) · 1.02 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
package unit_07.Examples.Example_07;
public class RectangleFigure {
private double length, width;
public RectangleFigure() {
length = 0;
width = 0;
}
public RectangleFigure(double length, double width) {
setDimension(length, width);
}
public void setDimension(double length, double width) {
if (length >= 0) {
this.length = length;
} else {
this.length = 0;
}
if (width >= 0) {
this.width = width;
} else {
this.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());
}
}