-
Notifications
You must be signed in to change notification settings - Fork 0
/
Goal.java
121 lines (100 loc) · 3.19 KB
/
Goal.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
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
package ProductObjects;
// Object class to contain the parameters the user has for their system
public class Goal {
public String goal;
public double budget;
public double sizeInKW; // user's desired energy
public double availableSpace; // in square meters
public double energyInVolts;
public Location location;
public Goal() {
}
public Goal(String goal) {
this.goal = goal;
}
public Goal(String goal, double budget, double energyInKW,
double availableSpace, Double[] coordinates) {
this.goal = goal;
this.budget = budget;
this.sizeInKW = energyInKW;
this.availableSpace = availableSpace;
this.energyInVolts = -1;
location = new Location(coordinates);
}
public Goal(String goal, double budget, double energyInKW,
double availableSpace, String address) {
this.goal = goal;
this.budget = budget;
this.sizeInKW = energyInKW;
this.availableSpace = availableSpace;
this.energyInVolts = -1;
location = new Location(address);
}
public Goal(String goal, double budget, double energyInKW,
double availableSpace, double energyInVolts, Double[] coordinates) {
this.goal = goal;
this.budget = budget;
this.sizeInKW = energyInKW;
this.availableSpace = availableSpace;
this.energyInVolts = energyInVolts;
location = new Location(coordinates);
}
public Goal(String goal, double budget, double energyInKW,
double availableSpace, double energyInVolts, String address) {
this.goal = goal;
this.budget = budget;
this.sizeInKW = energyInKW;
this.availableSpace = availableSpace;
this.energyInVolts = energyInVolts;
location = new Location(address);
}
// an object to store the location, which can either be an address (String)
// or coordinates (Double). Note that the PVWatts class will try to use the
// address string before the coordinates
public class Location {
private String address;
private double latitude, longitude;
public Location() {
}
// takes either an address or coordinates. If coordinates, submit as two
// doubles (lat, long). If an address, submit as a url-ready String
public Location(Object... location) {
setLocation(location);
}
public void setLocation(Object... location) {
if (location[0] instanceof Double) { // coordinates
if ((Double) location[0] > 90) {
System.out.println("latitude is too big");
System.exit(0);
} else if ((Double) location[1] > 180) {
System.out.println("longitude is too big");
System.exit(0);
}
latitude = ((Double) location[0]).doubleValue();
longitude = ((Double) location[1]).doubleValue();
address = null;
} else if (location[0] instanceof String) { // string address
address = urlFormat((String) location[0]);
latitude = longitude = 0;
} else {
System.out.println("Invalid Objects given to Location");
}
}
// converts an address to a url-implementable string
private String urlFormat(String address) {
address = address.replace(" ", "%20");
address = address.replace(",", "%2C");
address = address.replace(".", "");
return address;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public String getAddress() {
return address;
}
}
}