-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssueBasedAdvertisement.java
More file actions
57 lines (48 loc) · 1.86 KB
/
IssueBasedAdvertisement.java
File metadata and controls
57 lines (48 loc) · 1.86 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 IssueBasedAdvertisement extends Advertisement
{
/**
* Takes in Message and a candidate.
* Utilizes Super constructor----> Advertisement
* Method Overrides cost and triggers exception if candidate does not
* have enough money to generate the Issue Based Advertisement
*/
public IssueBasedAdvertisement(String inMsg, Candidate inCand) throws OutOfMoneyException
{
super(inMsg,inCand);
setCost(rand.nextInt(15001) + 5000);
if (getCost() > getCandidate().getMoney())
{
throw new OutOfMoneyException();
}
}
/**
* Prints information about Issue Based Advertisement
*/
public String toString()
{
return "This Issue-Based 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 Issue Based, Increase his Debate Modifier by .1 and return string approving message
* otherwise increase debate Modifier by .05 and return string not approving advertisement
*/
public String run()
{
if (getCandidate().getMoney() < getCost())
{
return "NO CASH";
}
getCandidate().addMoney(getCost() * -1);
if (getCandidate().endorse(this))
{
getCandidate().setDebateMod(getCandidate().getDebateMod() + .1);
return "My name is " + getCandidate().getName() + ", and I approve this message";
}
else
{
getCandidate().setDebateMod(getCandidate().getDebateMod() + .05);
return "This message has not been approved by " + getCandidate().getName() + ".";
}
}
}