-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTownHallAdvertisement.java
More file actions
57 lines (49 loc) · 1.92 KB
/
Copy pathTownHallAdvertisement.java
File metadata and controls
57 lines (49 loc) · 1.92 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
public class TownHallAdvertisement extends Advertisement
{
private int attendees = 0;
/**
* Takes in Message and a candidate.
* Utilizes Super constructor----> Advertisement
* Throws too Out of Money exception if advertisement cost is greater than Candidates money
*/
public TownHallAdvertisement(String inMsg, Candidate inCand) throws OutOfMoneyException
{
super(inMsg,inCand);
setCost(rand.nextInt(95001) + 5000);
attendees = rand.nextInt(151);
if (getCost() > getCandidate().getMoney())
{
throw new OutOfMoneyException();
}
}
/**
* Returns TownHall Advertisement information.
*/
public String toString()
{
return "This Town Hall Advert is:\n\tFor " + getCandidate().getName() + "\n\tAbout: " + getMessage() + "\n\tCosts: $" + getCost();
}
/**
* If candidates money is less then the cost required to run advert, returns a string
* If Candidates Advertisement Preference is Town Hall, Change Money Modifier to Attendees divided by 500+ modifier and return string approving message
* otherwise Change Money Modifier to Attendees divided by 2000 + modifier and return string approving message
*/
public String run()
{
if (getCandidate().getMoney() < getCost())
{
return "NO CASH";
}
getCandidate().addMoney(getCost() * -1);
if (getCandidate().endorse(this))
{
getCandidate().setMoneyMod(getCandidate().getMoneyMod() + (attendees / 500.0));
return getCandidate().getName() + " holds a successfull Town Hall.";
}
else
{
getCandidate().setMoneyMod(getCandidate().getMoneyMod() + (attendees / 2000.0));
return getCandidate().getName() + " holds a Town Hall.";
}
}
}