-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
110 lines (96 loc) · 2.19 KB
/
Circle.java
File metadata and controls
110 lines (96 loc) · 2.19 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* A Circle is a type of GeometricObject. In addition to the properties and
* behaviours
* of GeometricObject, it has a radius
*
* @author Ilias Markou
*/
public class Circle extends GeometricObject {
private double radius;
private double diameter;
private double perimeter;
/**
* Constructs a new circle with default value of radius as 1.0
*/
public Circle() {
this.radius = 1.0;
}
/**
* Constructs a new circle using the variable radius
*
* @param radius
*/
public Circle(double radius) {
this.radius = radius;
}
/**
* Constructs a new Circle using the inherited variables from the super class
* and the radius of this Circle
*
* @param radius
* @param color
* @param filled
*/
public Circle(double radius, String color, boolean filled) {
super(color, filled);
this.radius = radius;
}
/**
* The setRadius method sets the Circle's radius
*
* @param radius
*/
public void setRadius(double radius) {
this.radius = radius;
}
/**
* accessor method get Radius
*
* @return radius
*/
public double getRadius() {
return radius;
}
/**
* accessor method get Diameter
*
* @return diameter
*/
public double getDiameter() {
diameter = (2 * radius);
return diameter;
}
/**
* accessor method get Area
*
* @return area
*/
@Override
public double getArea() {
return Math.pow((3.14 * radius), 2);
}
/**
* accessor method get Perimeter
*
* @return perimeter
*/
@Override
public double getPerimeter() {
perimeter = 3.14 * diameter;
return perimeter;
}
/**
* @return String simple string showing properties of the circle
*/
@Override
public String toString() {
return super.toString() + ", radius: " + radius;
}
/** Overriden method scale which scales the Circle based on factor variable */
@Override
public void scale(double factor) {
if (factor > 0) {
radius = factor * radius;
}
}
}