-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandidate.java
More file actions
218 lines (189 loc) · 4.97 KB
/
Candidate.java
File metadata and controls
218 lines (189 loc) · 4.97 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
import java.util.Random;
public class Candidate
{
private String name = "DEFAULT";
private String slogan = "DEFAULT";
private int money = 0;
private static long allMoney = 0;
private String party = "DEFAULT";
private Random rand = new Random();
private int adPref = -1; // 0: IssueBased, 1: Attack, 2:TownHall
private int fundPref = -1; // 0: Social, 1: RotoCall, 2:PACs
private double moneyMod = 1.0;
private double debateMod = 1.0;
/**
* Returns information about Candidate
*/
public String toString()
{
String adType = "";
if (getAdPref() == 0)
{
adType = "Issue Based";
}
else if (getAdPref() == 1)
{
adType = "Attack";
}
else if (getAdPref() == 2)
{
adType = "Town Hall";
}
else
{
adType = "Unknown";
}
String fundType = "";
if (getAdPref() == 0)
{
fundType = "Social Events";
}
else if (getAdPref() == 1)
{
fundType = "Automated Phone Calls";
}
else if (getAdPref() == 2)
{
fundType = "Political Action Committees";
}
else
{
fundType = "Unknown";
}
return "Candidate " + getName() + ":\n\tSlogan: " + getSlogan() + "\n\tParty: " + getParty() + "\n\tCurrent funds: " + getMoney() + "\n\tPreferred Ad Type: " + adType + "\n\tPreferred Fund Type: " + fundType + "\n\tCurrent Money Modifier: " + getMoneyMod() + "\n\tCurrent Debate Modifier: " + getDebateMod() + "\n";
}
/**
*
* @param inName Candidates name from input file
* @param inSlogan Candidates slogan from input file
* @param inParty Candidates party from input file
*/
public Candidate(String inName, String inSlogan, String inParty)
{
setName(inName);
setSlogan(inSlogan);
setParty(inParty);
addMoney(rand.nextInt(101));
setAdPref(rand.nextInt(3));
setFundPref(rand.nextInt(3));
}
/**
* @param inName Candidates name being set
*/
public void setName(String inName)
{
name = inName;
}
/**
* returns Candidates Name
*/
public String getName()
{
return name;
}
/**
* @param inSlogan Candidates slogan is set from input file.
*/
public void setSlogan(String inSlogan)
{
slogan = inSlogan;
}
/**
* returns Slogan
*/
public String getSlogan()
{
return slogan;
}
/**
*
* @param inParty is Candidattes party from input file
*/
public void setParty(String inParty)
{
party = inParty;
}
public String getParty()
{
return party;
}
/**
*
* @return Candidates random amount of money set in Constructor
*/
public int getMoney()
{
return money;
}
public static long getAllMoney()
{
return allMoney;
}
public void addMoney(int newMoney)
{
money += newMoney;
allMoney +=newMoney;
}
/**
* Will return True if Advertisement passed in and Candidates preference are aligned,
* else will return false
*/
public boolean endorse(Advertisement newAd)
{
return (getAdPref() == 0 && newAd instanceof IssueBasedAdvertisement) || (getAdPref() == 1 && newAd instanceof AttackAdvertisement) || (getAdPref() == 2 && newAd instanceof TownHallAdvertisement);
}
/**
* Needed to compare Candidate names
*/
public boolean equals(Candidate otherCand)
{
return getName().equals(otherCand.getName());
}
/**
* Will compare two candidates based off money
*/
public int compareTo(Candidate otherCand)
{
return getMoney() - otherCand.getMoney();
}
public int getAdPref()
{
return adPref;
}
private void setAdPref(int newPref)
{
adPref = newPref;
}
public int getFundPref()
{
return fundPref;
}
private void setFundPref(int newPref)
{
fundPref = newPref;
}
public double getMoneyMod()
{
if (moneyMod < 0)
{
return 0;
}
return moneyMod;
}
public void setMoneyMod(double newMod)
{
moneyMod = newMod;
}
public double getDebateMod()
{
if (debateMod < 0)
{
return 0;
}
return debateMod;
}
public void setDebateMod(double newMod)
{
debateMod = newMod;
}
}