-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverallVote.java
More file actions
executable file
·302 lines (289 loc) · 7.45 KB
/
OverallVote.java
File metadata and controls
executable file
·302 lines (289 loc) · 7.45 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/**This class contains all of the objects with the individual votes for
* each demographic group.*/
import java.io.*;
import javax.swing.JOptionPane;
public class OverallVote implements Serializable{
//fields that hold the vote for each demographic group
private DemographicVote youth;
private DemographicVote workingAge;
private DemographicVote elderly;
private DemographicVote male;
private DemographicVote female;
private DemographicVote chinese;
private DemographicVote caucasian;
private DemographicVote asian;
private DemographicVote other;
//fields that holds whether the data has been saved
private boolean saved;
/**Constructor that will create the DemographicVote objects that will
* hold the votes as they are cast*/
public OverallVote()
{
//creates new objects and stores them in the fields
youth=new DemographicVote();
workingAge=new DemographicVote();
elderly=new DemographicVote();
male=new DemographicVote();
female=new DemographicVote();
chinese=new DemographicVote();
caucasian=new DemographicVote();
asian=new DemographicVote();
other=new DemographicVote();
saved=true;
}
/**Copy constructor that will create a copy of a OverallVote object that
* is passed as an argument.
* @param n the OverallVote object that is being copied*/
public OverallVote(OverallVote n)
{
//these statements create a deep copy of the OverallVote object
youth=new DemographicVote(n.youth.getObject());
workingAge=new DemographicVote(n.workingAge.getObject());
elderly=new DemographicVote(n.elderly.getObject());
male=new DemographicVote(n.male.getObject());
female=new DemographicVote(n.female.getObject());
chinese=new DemographicVote(n.chinese.getObject());
caucasian=new DemographicVote(n.caucasian.getObject());
asian=new DemographicVote(n.asian.getObject());
other=new DemographicVote(n.other.getObject());
saved=n.getSaved();
}
/**Method that allows the saved variable to be changed
* @param n the boolean value that will be stored in the saved variable*/
public void changeSaved(boolean n)
{
saved=n;
}
/**Method that allows access to the saved variable*/
public boolean getSaved()
{
return saved;
}
/**Method creates and returns a copy of the object.
* @return copy of current OverallVote object*/
public OverallVote getObject()
{
//return statement that will return a deep copy of the object
return new OverallVote(this);
}
/**Method that will add votes into the selected demographic choice
* @param n the number representing the demographic group
* @param m the number representing the candidate*/
public void tallyVote(int n, int m)
{
//if else statements to determine which demographic group was chosen
if(n==1)
{
if(m==1)
youth.addVote(m);
else if(m==2)
youth.addVote(m);
else if (m==3)
youth.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else if(n==2)
{
//select the right candidate to who the vote was for
//add vote to the candidate
if(m==1)
workingAge.addVote(m);
else if(m==2)
workingAge.addVote(m);
else if (m==3)
workingAge.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else if(n==3)
{
//select the right candidate to who the vote was for
//add vote to the candidate
if(m==1)
elderly.addVote(m);
else if(m==2)
elderly.addVote(m);
else if (m==3)
elderly.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else if(n==4)
{
//select the right candidate to who the vote was for
//add vote to the candidate
if(m==1)
male.addVote(m);
else if(m==2)
male.addVote(m);
else if (m==3)
male.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else if(n==5)
{
//select the right candidate to who the vote was for
//add vote to the candidate
if(m==1)
female.addVote(m);
else if(m==2)
female.addVote(m);
else if (m==3)
female.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else if(n==6)
{
//select the right candidate to who the vote was for
//add vote to the candidate
if(m==1)
chinese.addVote(m);
else if(m==2)
chinese.addVote(m);
else if (m==3)
chinese.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else if(n==7)
{
//select the right candidate to who the vote was for
//add vote to the candidate
if(m==1)
caucasian.addVote(m);
else if(m==2)
caucasian.addVote(m);
else if (m==3)
caucasian.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else if(n==8)
{
//select the right candidate to who the vote was for
//add vote to the candidate
if(m==1)
asian.addVote(m);
else if(m==2)
asian.addVote(m);
else if (m==3)
asian.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else if(n==9)
{
//select the right candidate to who the vote was for
//add vote to the candidate
if(m==1)
other.addVote(m);
else if(m==2)
other.addVote(m);
else if (m==3)
other.addVote(m);
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
}
}
/**Method that will get the votes for the selected demographic group and candidate
* @param n the number representing each demographic and the candidate inside that demographic*/
public int getVote(int n)
{
//if else if statements to select which candidate in which demographic group to return
if(n==1)
return youth.getLiberal();
else if(n==2)
return youth.getNDP();
else if(n==3)
return youth.getGreen();
else if(n==4)
return workingAge.getLiberal();
else if(n==5)
return workingAge.getNDP();
else if(n==6)
return workingAge.getGreen();
else if(n==7)
return elderly.getLiberal();
else if(n==8)
return elderly.getNDP();
else if(n==9)
return elderly.getGreen();
else if(n==10)
return male.getLiberal();
else if(n==11)
return male.getNDP();
else if(n==12)
return male.getGreen();
else if(n==13)
return female.getLiberal();
else if(n==14)
return female.getNDP();
else if(n==15)
return female.getGreen();
else if(n==16)
return chinese.getLiberal();
else if(n==17)
return chinese.getNDP();
else if(n==18)
return chinese.getGreen();
else if(n==19)
return caucasian.getLiberal();
else if(n==20)
return caucasian.getNDP();
else if(n==21)
return caucasian.getGreen();
else if(n==22)
return asian.getLiberal();
else if(n==23)
return asian.getNDP();
else if(n==24)
return asian.getGreen();
else if(n==25)
return other.getLiberal();
else if(n==26)
return other.getNDP();
else if(n==27)
return other.getGreen();
else
{
JOptionPane.showMessageDialog(null, "Problem with Program. Progam terminating.");
System.exit(0);
return 0;
}
}
}