-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttackAdvertisement.java
More file actions
92 lines (86 loc) · 3.41 KB
/
AttackAdvertisement.java
File metadata and controls
92 lines (86 loc) · 3.41 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
import java.util.*;
/**
* The AttackAdvertisement is used to simulate a Candidate attacking another Candidate
* AttackAdvertisement is a subclass of Advertisement, it has a cost, Target Candidate, Candidate running the add and a Type
* The cost determines how much money a Candidate must have in order to run the AttackAdvertisement
* TargetCand is the Candidate that's being attacked by the AttachAd
* Type helps tell that the AttackAdvertisement is a "Attack Ads"
* @author Fuad Mohamoud
*/
public class AttackAdvertisement extends Advertisement
{
private Candidate target = null;
/**
* Full Parameter Constructor to build an AttackAdvertisement using the inputed parameter values provided
* @param adCand will become the candidate running the Ad
* @param targetCand will become thee Candidate being attached by the Ad
* @throws OutOfMoneyException is thrown when the Ad's cost is greater than Candidate's money value
*/
public AttackAdvertisement(Candidate adCand, ArrayList<Candidate> targetCand) throws OutOfMoneyException
{
setType("Attack Ads");
setCost(rand.nextInt(25001)+50000);
setCandidate(adCand);
setTarget(targetCand);
setMessage("This is an Attack Advertisement for " + ourCand.getName());
if(cost > adCand.getMoney())
{
throw new OutOfMoneyException();
}
}
/**
*toString Overrided Superclass's toString to output useful information about the AttackAd
* Information display are, the cost of the Ad, the Candidate running the Ad, and the Target of the Ad
* @return String containing specific information about the AttackAdvertisement
*/
public String toString()
{
String output="This is an Attack Advertisement. \n\tIt costs " + getCost() + " dollars. \n\tIt's Candidate is " + ourCand.getName() + ". \n\tIt targets " + target.getName();
return output;
}
/**
*setTarget updates the Candidate that's the target of the attackAd
* Randomly selected from Arraylist of Candidate, verifies that Candidate is not attacking self
* @param targets current AttackAdvertisement's target
*/
public void setTarget(ArrayList<Candidate> targets)
{
target = targets.get(rand.nextInt(targets.size()));
while(target.equals(ourCand))
{
target = targets.get(rand.nextInt(targets.size()));
}
}
/**
*getTarget allows access to the Candidate's current Target
* @return the AttackAdvertisement's current Target Candidate
*/
public Candidate getTarget()
{
return target;
}
/**
* RunAd is a Method used Change a candidate's debate modifier and Money modifier after an AttackAd is been executed
* RunAd changed the Money mod, deb mod for both the Target ad and Ad running the Attackad
* @return string indicating wither ad was approved by Candidate or not
*/
public String runAd()
{
if(ourCand.endorse(this) == true)
{
ourCand.setDebateMod(.2 + ourCand.getDebateMod());
ourCand.setMoneyMod(ourCand.getMoneyMod() - .2);
target.setDebateMod(target.getDebateMod() - .15);
target.setMoneyMod(target.getMoneyMod() - .25);
return "My name is " + ourCand.getName() + " and I approve this message.";
}
else
{
ourCand.setDebateMod(.1 + ourCand.getDebateMod());
ourCand.setMoneyMod(ourCand.getMoneyMod() - .05);
target.setDebateMod(target.getDebateMod() - .05);
target.setMoneyMod(target.getMoneyMod() - .1);
return "This message has not been approved by " + ourCand.getName();
}
}
}