forked from mouredev/hello-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
43 lines (34 loc) · 909 Bytes
/
Copy pathRectangle.java
File metadata and controls
43 lines (34 loc) · 909 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
package basic.c08_oop;
public class Rectangle extends Shape {
private double width;
private double height;
public Rectangle(double width, double height) {
setWidth(width);
setHeight(height);
}
public void setWidth(double width) {
if (width > 0)
this.width = width;
else
System.out.println("Ancho no válido, debe ser mayor que 0");
}
public void setHeight(double height) {
if (height > 0)
this.height = height;
else
System.out.println("Alto no válido, debe ser mayor que 0");
}
public double getWidth() {
return width;
}
public double getHeight() {
return height;
}
@Override
public double calculateArea() {
return width * height;
}
public double calculatePerimeter() {
return 2 * (width + height);
}
}