-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometricObject.java
More file actions
136 lines (118 loc) · 2.88 KB
/
GeometricObject.java
File metadata and controls
136 lines (118 loc) · 2.88 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* A GeometricObject has a color, a dateCreated, and a boolean filled.
*
* @author Paul Nulty
*/
import java.util.Date;
/**
* Geometric Object abstract class implements the Comparable and Scalable
* interface
*
* @author Ilias Markou
*/
public abstract class GeometricObject implements Comparable<GeometricObject>, Scalable {
private String color; // The color
private boolean filled; // Filled (true for yes)
private Date dateCreated; // The date of creation
/**
* The Comparable interface compares Geometric Objects based on area
*
* @param GeometricObject
*
*/
public interface Comparable<T> {
// compare to method using placeholder
int compareTo(T other);
}
/**
* The Scalable interface uses the scale method to scale the Object based on the
* variable factor
* For Circle,the method scale multiplies the radius by the parameter factor.
* For Rectangle, the scale method multiplies both the width and the height by
* the parameter factor.
* For both Circle and Rectangle, if factor ≤ 0, the values of the instance
* variable(s) remains unchanged.
*
* @param factor
*
*/
public interface Scalable {
// Abstract method scale
public abstract void scale(double factor);
}
/**
* Construct a default GeometricObject with color white, unfilled
*/
protected GeometricObject() {
this("white", false);
}
/**
* Construct a GeometricObject with the specified color and filled value,
* initialise the dateCreated
*
* @param color color of the shape
* @param filled is the shape filled in - true for yes
*/
protected GeometricObject(String color, boolean filled) {
this.color = color;
this.filled = filled;
dateCreated = new Date();
}
/**
* @return String color accessor
*/
public String getColor() {
return color;
}
/**
* @param color color to set
*/
public void setColor(String color) {
this.color = color;
}
/**
* @return boolean color accessor
*/
public boolean isFilled() {
return filled;
}
/**
* @param filled set the boolean value for filled
*/
public void setFilled(boolean filled) {
this.filled = filled;
}
/**
* @return Date date accessor
*/
public Date getDateCreated() {
return dateCreated;
}
// Abstract method getArea
public abstract double getArea();
// Abstract method getPerimeter
public abstract double getPerimeter();
/**
* The compareTo method overrides the Comparable interface's method to compare
* Geometric Objects based on area
*
* @param GeometricObject
*/
@Override
public int compareTo(GeometricObject o) {
if (this.getArea() < o.getArea()) {
return -1;
} else if (this.getArea() > o.getArea()) {
return 1;
} else {
return 0;
}
}
/**
* @return String return a string describing the GeometricObject
*/
@Override
public String toString() {
return "created: " + dateCreated + ", color: " + color + ", filled: " + filled;
}
}