-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTownHallAdvertisement.java
More file actions
77 lines (70 loc) · 2.61 KB
/
TownHallAdvertisement.java
File metadata and controls
77 lines (70 loc) · 2.61 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
import java.util.ArrayList;
/**
* The TownHallAdvertisement class is used to simulate a TownHall Advertisement
* The TownHallAdvertisement is a subclass of Advertisement
* @author Fuad Mohamoud
*/
public class TownHallAdvertisement extends Advertisement
{
private int attendees=0;
/**
* Full Parameter Constructor to build a TownHallAdvertisement using the inputted parameter values provided
* @param adCand will be used as the Candidate running the TownHall Advertisement
* @throws OutOfMoneyException is thrown when the TownHallAdvertisement's cost is greater than Candidate's money value
*/
public TownHallAdvertisement(Candidate adCand) throws OutOfMoneyException
{
setType("Town Hall");
setCost(rand.nextInt(95001)+5000);
setCandidate(adCand);
setAttend();
setMessage("This is an Town Hall Advertisement for " + ourCand.getName());
if(cost > adCand.getMoney())
{
throw new OutOfMoneyException();
}
}
/**
* RunAd is a Method used Change a candidate's debate modifier and Money modifier after TownHall Advertisement been executed
* RunAd changed the Money modifier for the candidate conducting the Advertisement
* @return string indicating wither the TownHall Advertisement was successfully or not
*/
public String runAd()
{
if(ourCand.endorse(this) == true)
{
ourCand.setMoneyMod(ourCand.getMoneyMod() + (attendees/500.0));
return ourCand.getName() + " holds a successful Town Hall.";
}
else
{
ourCand.setMoneyMod(ourCand.getMoneyMod() + (attendees/2000.0));
return ourCand.getName() + " holds a Town Hall.";
}
}
/**
*setAttend randomly updates the number of people attending the TownHall Advertisement
* No param needed as it Random
*/
public void setAttend()
{
attendees=rand.nextInt(151);
}
/**
*getAttend allows access to the number of people attending the TownHall Advertisement
* @return the value for attendees
*/
public int getAttend()
{
return attendees;
}
/**
*toString is method used to output specific information about the current TownHallAdvertisement
* @return an output string indicating the cost of it, the candidate conducting a TownHall Advertisement and number of people attending the TownHall Advertisement
*/
public String toString()
{
String output="This is a Town Hall Advertisement. \n\tIt costs " + getCost() + " dollars. \n\tIt's Candidate is " + ourCand.getName() + " \n\tIt had " + getAttend() + " attendees.";
return output;
}
}