-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState.java
132 lines (117 loc) · 1.95 KB
/
State.java
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//Camryn Bickerstaff
//
//
import java.util.*;
public class State
{
private String state, party;
private int population, electoral;
int populationVote = 0; int vote = 0;
int republicanVote = 0;
int democratVote = 0;
public State(String s, int p, int e, String pa)
{
state = s;
population = p;
electoral = e;
party = pa;
}
public void populationVotes()
{
populationVote = (int)(population*(.4));
}
public void getVotes()
{
republicanVote = 0;
democratVote = 0;
if(party.equals("D"))
{
for(int i = 0; i <= populationVote; i++)
{
vote = ((int)((Math.random()*100)+1));
if(vote <= 51)
{
democratVote = democratVote + 1;
}
else
{
republicanVote = republicanVote + 1;
}
}
}
else if(party.equals("R"))
{
for(int i = 0; i <= populationVote; i++)
{
vote = ((int)((Math.random()*100)+1));
if(vote <= 51)
{
republicanVote = republicanVote + 1;
}
else
{
democratVote = democratVote + 1;
}
}
}
else if(party.equals("S"))
{
for(int i = 0; i <= populationVote; i++)
{
vote = ((int)(Math.random()*2)+1);
if(vote == 1)
{
republicanVote = republicanVote + 1;
}
else if(vote == 2)
{
democratVote = democratVote + 1;
}
}
}
if(democratVote == republicanVote)
{
vote = ((int)(Math.random()*2)+1);
if(vote == 1)
{
republicanVote = republicanVote + 1;
}
else if(vote == 2)
{
democratVote = democratVote + 1;
}
}
}
public int getDemVotes()
{
return democratVote;
}
public int getRepVotes()
{
return republicanVote;
}
public int getElectoralVote()
{
return electoral;
}
public String getName()
{
return state;
}
public String getParty()
{
if(party.equals("R"))
{
return "Republican";
}
else if(party.equals("D"))
{
return "Democratic";
}
else if(party.equals("S"))
{
return "Swing";
}
return "";
}
}