-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebate.java
More file actions
94 lines (85 loc) · 2.58 KB
/
Debate.java
File metadata and controls
94 lines (85 loc) · 2.58 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
/**
* Fuad Mohamoud
* Computer Science II
* 01/29/2106
*/
import java.util.Random;
public class Debate
{
private String location = "DEFAULT";
private Candidate[] candidates = new Candidate[2];
private Random rand = new Random();
/**
* Debate Constructor takes in Location
* along with 2 candidates that will be
* debating
*/
public Debate(String inLoc, Candidate inC1, Candidate inC2)
{
setLocation(inLoc);
setCandidates(inC1, inC2);
}
/**
* Sets location equal to one provided in constructor
*/
public void setLocation(String inLoc)
{
location = inLoc;
}
/**
* Returns location
*/
public String getLocation()
{
return location;
}
/**
* Takes in two candidates. First checks to see if they are equal
* We dont want the same candidate debating him or herself.
* Then if all is good, we set each candidate to a index in an Array.
*/
public void setCandidates(Candidate inC1, Candidate inC2)
{
if (inC1 == inC2) //Same place in memory, must be same Candidate!
{
return; //No self debates!!!
}
candidates[0] = inC1;
candidates[1] = inC2;
}
/**
* Returns Candidates Debating
*/
public String getCandidates()
{
return candidates[0].getName() + " VERSUS " + candidates[1].getName();
}
/**
* Sets two variables to random numbers
* The greater number determines who won or lost the debate
* Winning Candidate gets the losing candidates money
* Losing Candidate gets money set to zero.
*/
public String declareWinner()
{
int c1Points = 0;
int c2Points = 0;
while (c1Points == c2Points)
{
c1Points = rand.nextInt(100);
c2Points = 100 - c1Points;
}
if (c1Points > c2Points)
{
candidates[0].addMoney(candidates[1].getMoney());
candidates[1].addMoney(-1 * candidates[1].getMoney());
return candidates[0].getName() + " won the debate by " + (c1Points - c2Points) + " points.";
}
else
{
candidates[1].addMoney(candidates[0].getMoney());
candidates[0].addMoney(-1 * candidates[0].getMoney());
return candidates[1].getName() + " won the debate by " + (c2Points - c1Points) + " points.";
}
}
}