-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtroposCircle.java
More file actions
executable file
·219 lines (186 loc) · 5.02 KB
/
AtroposCircle.java
File metadata and controls
executable file
·219 lines (186 loc) · 5.02 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/**
* @file AtroposCircle.java
* @author Kyle Burke <paithan@cs.bu.edu>
* @date
*
* @brief This defines one circle of the sperner triangle.
*
*/
//package something;
//import java.lang.*;
//import java.io.*;
import java.util.*;
public class AtroposCircle {
/**
* Blank Color.
*/
private static final int UNCOLORED = 0;
/**
* Color Red.
*/
private static final int RED = 1;
/**
* Color Blue.
*/
private static final int BLUE = 2;
/**
* Color Green.
*/
private static final int GREEN = 3;
/**
* Color of the circle.
*/
private int color;
/**
* Height of the circle (0 = bottom).
*/
private int height;
/**
* Distance from the left side of the triangle (0 = on the left side).
*/
private int leftDistance;
/**
* Distance form the right side of the triangle (0 = on the right side).
*/
private int rightDistance;
/**
* Class constructor. Creates an empty circle.
*
* @param height Height of the circle.
* @param leftDistance Left Distance of the circle.
* @param rightDistance Right Distance of the circle.
*/
public AtroposCircle(int height, int leftDistance,
int rightDistance) {
this.color = UNCOLORED;
this.height = height;
this.leftDistance = leftDistance;
this.rightDistance = rightDistance;
}
/**
* Class constructor. Creates an colored circle.
*
* @param color Color of the circle.
* @param height Height of the circle.
* @param leftDistance Left Distance of the circle.
* @param rightDistance Right Distance of the circle.
*/
public AtroposCircle(int color, int height, int leftDistance,
int rightDistance) {
if (color > 3 || color < 0) {
System.out.println("Error: Not a legal color!");
}
this.color = color;
this.height = height;
this.leftDistance = leftDistance;
this.rightDistance = rightDistance;
}
public AtroposCircle clone() {
return new AtroposCircle(this.color, this.height, this.leftDistance, this.rightDistance);
}
/**
* Colors an uncolored circle.
*
* @param color New color for this.
*/
public void color(int color) {
if (this.color != UNCOLORED) {
System.out.println("Error: This circle is already colored!");
return;
}
this.color = color;
}
/**
* Returns the color of this.
*/
public int getColor() {
return this.color;
}
/**
* Returns the height of this.
*/
public int height() {
return this.height;
}
/**
* Returns the left distance of this.
*/
public int leftDistance() {
return this.leftDistance;
}
/**
* Returns the right distance of this.
*/
public int rightDistance() {
return this.rightDistance;
}
/**
* Determines whether a circle is colored.
*
*/
public boolean isColored() {
return this.color != UNCOLORED;
}
/**
* Determines whether this circle is adjacent to another.
*
* @param circle Circle we're comparing with.
*/
public boolean adjacentTo(AtroposCircle circle) {
return (((Math.abs(this.height - circle.height()) == 1) &&
(this.leftDistance == circle.leftDistance())) ||
((Math.abs(this.leftDistance -
circle.leftDistance()) == 1) &&
(this.height == circle.height())) ||
((Math.abs(this.height -
circle.height()) == 1) &&
(this.rightDistance == circle.rightDistance())));
}
/**
* Determines whether this circle is in a board of the given size.
*
* @param size Size of the board.
*/
public boolean insideBoardOfSize(int size) {
//this test removes the corners
if (this.height == size ||
this.leftDistance == size ||
this.rightDistance == size) {
return false;
}
//then just make sure it's inside the board
return (this.height + this.leftDistance + this.rightDistance == size);
}
public String getLocationString() {
return "(" + this.height + ", " + this.leftDistance + ", " +
this.rightDistance + ")";}
public String getColorLocationString() {
return "(" + this.color + ", " + this.height + ", " + this.leftDistance + ", " + this.rightDistance + ")";}
/**
* Returns a string version of this.
*
* @param indent Indentation string.
*/
public String toString(String indent){
String string = "";
string += "Circle colored " + this.color + " at: (" +
this.height + ", " + this.leftDistance + ", " +
this.rightDistance + ").\n";
return string;
}
/**
* Returns a string version of this.
*/
public String toString() {
return this.toString("");
}
/**
* Main method for testing.
*/
public static void main(String[] args) {
AtroposCircle circle = new AtroposCircle(0, 1, 2);
System.out.println(circle.toString());
circle.color(RED);
System.out.println(circle.toString());
}
} //end of AtroposCircle.java