-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.java
49 lines (38 loc) · 936 Bytes
/
Circle.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
package prg.es4;
import prg.es2.Scalable;
import prg.es2.Drawable;
public class Circle extends Shape{
private double radius;
//COSTRUTTORI:
public Circle(){}
public Circle(int radius){
this.setRadius(radius);
}
//METODI:
public Circle setRadius(int radius){
this.radius = Math.abs(radius);
return this;
}
public double getRadius(){
return this.radius;
}
@Override
public double perimeter(){
return 2*Math.PI*this.getRadius();
}
@Override
public double area(){
return Math.PI*Math.pow(this.getRadius(), 2);
}
public String toString(){
return "Circle, " + super.toString() +", Radius: " + this.getRadius() + ", Perimeter: " + Math.round(this.perimeter()) + ", Area: " + Math.round(this.area());
}
@Override
public void draw(){
System.out.println(this.toString());
}
@Override
public void scale(double factor){
this.radius *= factor;
}
}