-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.java
62 lines (48 loc) · 1.2 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
56
57
58
59
60
61
62
package prg.es4;
import prg.es2.Scalable;
import prg.es2.Drawable;
public class Rectangle extends Shape{
private double width;
private double length;
//COSTRUTTORI:
public Rectangle(){}
public Rectangle(int width, int length){
this.setWidth(Math.abs(width));
this.setLength(Math.abs(length));
}
//METODI:
public Rectangle setWidth(int width){
this.width = Math.abs(width);
return this;
}
public Rectangle setLength(int length){
this.length = Math.abs(length);
return this;
}
public double getWidth(){
return this.width;
}
public double getLength(){
return this.length;
}
@Override
public double perimeter(){
return 2*this.getWidth() + 2*this.getLength();
}
@Override
public double area(){
return this.getWidth() * this.getLength();
}
public String toString(){
return "Rectangle, " + super.toString() +", Width: " + this.getWidth() + ", Length: " + this.getLength() + ", Perimeter: " + this.perimeter() + ", Area: " + this.area();
}
@Override
public void draw(){
System.out.println(this.toString());
}
@Override
public void scale(double factor){
this.width *= factor;
this.length *= factor;
}
}