-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandidate.java
More file actions
381 lines (337 loc) · 9.91 KB
/
Candidate.java
File metadata and controls
381 lines (337 loc) · 9.91 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/**
* The Candidate class is used to simulate a presidential Candidate
* A Candidate has a name, slogan message, money, is a member of a political Party,
* MoneyMod, debateMod, adPreference, fund preference and a debate score
* <br><br>
* @author Fuad Mohamoud
*/
import java.util.Random;
import java.lang.*;
import java.util.*;
public class Candidate implements Comparable<Candidate>
{
private String name = "DEFAULT";
private String slogan = "DEFAULT";
private double money = 0;
private String party = "DEFAULT";
private Random rand = new Random();
private double moneyMod= 0.0;
private double debateMod=0.0;
private String adPreference="DEFAULT";
private Fundraiser fundPreference=null;
private double debscore=0;
/**
*setDebscore updates the Candidate's debatescore
* @param indebscore value which will become the Candidate's new dabate score
*/
public void setDebscore(double indebscore)
{
debscore=indebscore;
}
/**
*getDebscore allows access to the Candidate's debate score value
* @return the Candidate's current debate score
*/
public double getDebscore()
{
return debscore;
}
/**
*equalsParty is method used determine if Candidate is in the same political party as another Candidate
* @param otherCand Candidate to compare the party with- different cand
* @return boolean if two Candidate have the are in the same Party
*/
public boolean equalsParty(Candidate otherCand)
{
if(getParty().equals(otherCand.getParty()))
{
return true;
}
return false;
}
/**
*equals is a methond used to determine wither two Candidate's have the same name.
* @param otherCandidate
* @return true or false if two candidates have the same name-
*/
public boolean equals(Candidate otherCandidate)
{
if (getName().equals(otherCandidate.getName()))
{
return true;
}
return false;
}
/**
*toString method is used to display specific information about the Candidate
* @return String containing the name, Slogan, money and the party.
*/
public String toString()
{
String output="This Candidate's name is " + getName()+":\n\tTheir slogan is " + getSlogan() +
"\n\tThe candidate has "+ "$"+String.format("%.2f",getMoney())+ "\n\t" + getName() + " is a party member of \"" + getParty() +
"\"";
return output;
}
/**
*compareTo is used to determine if two Candidate's have the same money value
* @param otherCandidate Candidate to compare money value with
* @return 0 if two candidate have the same money value, -1 if current has less money and 1 if Current cand has more money
*/
public int compareTo(Candidate otherCandidate)
{
int x= (int)this.getMoney();
int g = (int)otherCandidate.getMoney();
if(x-g==0)
{
return this.getName().compareTo(otherCandidate.getName());
}
else
{
return x-g;
}
}
/**
*setAdpreference is a method used to Randomly determine the Candidate's Adpreference
* Candidate can either prefer to run, issue-based ads, Attack ads or Town Hall.
* Method helps determine if the Candidate approves the Ad or not
*/
private void setAdpreference()
{
int ad=rand.nextInt(3);
if (ad==0)
{
adPreference="Issue-Based";
}
else if (ad==1)
{
adPreference="Attack Ads";
}
else
{
adPreference="Town Hall";
}
}
/**
*getAdpreference allows access to the Candidate's Adpreference
* @return the Candidate's Adpreference
*/
public String getAdpreference()
{
return adPreference;
}
/**
*setFundrasingprefer is a method used to Randomly determine the Candidate's Fundrasingprefer
* Candidate can either select Social Events,Automated Phone Calls, Political Action Committees"
* Method helps determine the fundraiser type that they prefer to go to
*/
private void setFundrasingprefer()
{
int ad=rand.nextInt(3);
if(ad == 0)
{
// fundPreference="Social Events";
fundPreference= new SocialFundraiser();
}
else if (ad==1)
{
// fundPreference="Automated Phone Calls";
fundPreference= new PhoneFundraiser();
}
else
{
// fundPreference="Political Action Committees";
fundPreference= new PACFundraiser();
}
}
/**
*getFundraisingprefer allows access the Candidate's current Fundraising prefer
* @return Fundraising prefer
*/
public Fundraiser getFundraisingprefer()
{
return fundPreference;
}
/**
*Pull Parameter constructor to build a Candidate using the inputed parameter value provided
* @param inName will be used as the Candidate's Name
* @param inSlogan will be used as the Candidate's Slogan
* @param inParty will be used as the Candidate's Party
*/
public Candidate(String inName, String inParty, String inSlogan)
{
setName(inName);
setSlogan(inSlogan);
setParty(inParty);
money = rand.nextDouble()*100;
setMoneyMod(1.0);
setDebateMod(1.0);
setFundrasingprefer();
setAdpreference();
}
/**
*setMoneyMod update's the Candidate's Money modifier value
* @param inMod is the value which will become the Candidate's new Money Modifier rating
*/
public void setMoneyMod(double inMod)
{
moneyMod=inMod;
}
/**
*getMoneyMod allows access the the Candidate's money modifier
* @return the candidate's current Money Modifier rating
*/
public double getMoneyMod()
{
if (moneyMod < 0)
{
return 0;
}
return moneyMod;
}
/**
*setDebateMod update's the Candidate's debate modifier value
* @param inMod is the value which will become the Candidate's new debate Modifier rating
*/
public void setDebateMod(double inMod)
{
debateMod=inMod;
}
/**
*getDebateMod allows access the the Candidate's debate modifier
* @return the candidate's current debate Modifier rating
*/
public double getDebateMod()
{
if (debateMod < 0)
{
return 0;
}
else
{
return debateMod;
}
}
/**
*setName updates the Candidate's Name
* @param inName is the Value which will become the Candidate's new Name
*/
public void setName(String inName)
{
name = inName;
}
/**
*getName allows access to the Candidate's name
* @return the Candidate's current Name
*/
public String getName()
{
return name;
}
/**
*setSlogan updates Candidate's Slogan
* @param inSlogan is the value that will become the Candidate's new slogan
*/
public void setSlogan(String inSlogan)
{
slogan = inSlogan;
}
/**
*getSlogan allows access to the Candidate's Slogan
* @return the Candidate's current Slogan
*/
public String getSlogan()
{
return slogan;
}
/**
*setParty updates Candidate's Party
* @param inParty is the value that will become the Candidate's new Party
*/
public void setParty(String inParty)
{
party = inParty;
}
/**
*getParty allows access to the Candidate's Party
* @return the Candidate's current Party
*/
public String getParty()
{
return party;
}
/**
* getMoney allows access to the Candidate's money value
* @return the candidate's current money value
*/
public double getMoney()
{
if(money <= 0.0)
{
money = 0.00;
return money;
}
else
{
return money;
}
}
/**
*addMoney is a method for adding money to the Candidate current money value
* @param newMoney is value that will be added to Candidate's money
*/
public void addMoney(double newMoney)
{
money += newMoney;
}
/**
* endorse is a method for Candidate to endorse something
* @return String value containing his name
*/
public boolean endorse(Advertisement advert)
{
if(adPreference.equals(advert.getType()))
{
return true;
}
else
{
return false;
}
}
/**
* simpleAI is a method which changes the candidate's Ad and Fundraiser preferences
* if the candidate is too far behind in the race and it is before day 305
* @param cands is an ArrayList of ArrayLists which hold the candidates sorted by party
*/
public void simpleAI(ArrayList<ArrayList<Candidate>> cands)
{
for(ArrayList<Candidate> curr: cands)
{
for(int x = 0; x < curr.size(); x++)
{
if(curr.get(x).getMoney() < curr.get(0).getMoney()/100)
{
curr.get(x).setFundrasingprefer();
curr.get(x).setAdpreference();
}
}
}
}
/**
* simpleAI2 is a method which changes the candidate's Ad and Fundraiser preferences
* if the candidate is too far behind in the race and it is after day 305
* @param cands is an ArrayList which holds the remaining candidates
*/
public void simpleAI2(ArrayList<Candidate> cands)
{
for(Candidate curr: cands)
{
if(curr.getMoney() < cands.get(0).getMoney()/100)
{
curr.setFundrasingprefer();
curr.setAdpreference();
}
}
}
}