-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemographicVote.java
More file actions
executable file
·74 lines (64 loc) · 1.91 KB
/
DemographicVote.java
File metadata and controls
executable file
·74 lines (64 loc) · 1.91 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
/**This class is designed to store the vote of different demographic groups.
* The class will tally the votes then return them when the program asks.*/
import java.io.*;
public class DemographicVote implements Serializable{
//private fields to hold the votes for each party
private int liberal;
private int ndp;
private int green;
/**The constructor will initialize the votes for each private field to zero*/
public DemographicVote()
{
//initialize the votes to zero
liberal=0;
ndp=0;
green=0;
}
/**Copy constructor will create a copy of the object in new memory space*/
public DemographicVote(DemographicVote n)
{
//copy all three private fields from object that was passed
liberal=n.getLiberal();
ndp=n.getNDP();
green=n.getGreen();
}
/**This method will add the votes to a particular political party*/
public void addVote(int n)
{
//if statements to determine where vote will be placed
if(n==1)
liberal++;
if(n==2)
ndp++;
if(n==3)
green++;
}
/**This method will return the number of votes the liberal party received
* from the particular demographic group
* @return the number of liberal votes for particular demographic*/
public int getLiberal()
{
return liberal;
}
/**This method will return the number of votes the ndp party received
* from the particular demographic group
* @return the number of ndp votes for particular demographic*/
public int getNDP()
{
return ndp;
}
/**This method will return the number of votes the green party received
* from the particular demographic group
* @return the number of green votes for particular demographic*/
public int getGreen()
{
return green;
}
/**This method will return a copy of the current object
* @return copy of current DemographicVote object*/
public DemographicVote getObject()
{
//statement that will return a copy of the data in this object
return new DemographicVote(this);
}
}