-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
58 lines (49 loc) · 1.24 KB
/
Point.java
File metadata and controls
58 lines (49 loc) · 1.24 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
package simulator;
/*
* Class point is a point on the graph and also a possible candidate
* solution for the problem.
*/
public class Point {
// x,y coords of point and its solution
private double x;
private double y;
private double fitness;
// flags to check whether or not coords and soln are initialized before
// getting them
private Boolean isCoordSet = false;
private Boolean isFitnessSet = true;
// constructor to init points
Point(double d, double e) {
isCoordSet = true;
this.x = d;
this.y = e;
}
@Override
public String toString() {
return "(" + this.x + "," + this.y + "):" + this.fitness;
}
// set solution to this point object
public void setFitness(double f) {
isFitnessSet = true;
this.fitness = f;
}
// getters for x, y and solution
public double getX() throws PointUsageException {
if (isCoordSet)
return this.x;
else
throw new PointUsageException("coords not set");
}
public double getFitness() throws PointUsageException {
if (isFitnessSet)
return this.fitness;
else
throw new PointUsageException("fitness for this point not set yet");
}
public double getY() throws PointUsageException {
if (isCoordSet)
return this.y;
else
throw new PointUsageException("coords not set");
}
}