Java Reference
In-Depth Information
candidatesName
votesByRegion
totalVotes
[0]
23
25
110
134
56
207
[1]
89
71
158
112
63
56
[2]
0
89
0
156
67
0
[3]
160
97
0
0
89
46
[0]
Ashley
Danny
Donald
Mia
Mickey
Peter
[0]
0
0
0
0
0
0
[0]
[1]
[1]
[1]
[2]
[2]
[2]
[3]
[3]
[3]
[4]
[4]
[4]
[5]
[5]
[5]
FIGURE 14-22 Arrays candidatesName , votesByRegion ,and totalVotes after
processing the voting data
After calculating the total votes received by each candidate, the three arrays are as
shown in Figure 14-23.
candidatesName
votesByRegion
totalVotes
[0]
23
25
110
134
56
207
[1]
89
71
158
112
63
56
[2]
0
89
0
156
67
0
[3]
160
97
0
0
89
46
[0]
Ashley
Danny
Donald
Mia
Mickey
Peter
[0]
272
282
268
402
275
309
[0]
[1]
[1]
[1]
[2]
[2]
[2]
[3]
[3]
[3]
[4]
[4]
[4]
[5]
[5]
[5]
FIGURE 14-23 Arrays candidatesName , votesByRegion ,and totalVotes after
calculating the total votes received by each candidate
To calculate the total votes received by each candidate, we add the contents of each
row in the votesByRegion array and store the sum in the corresponding row in the
totalVotes array. This is accomplished by the method addRegionsVote , which is
described next.
The method addRegionsVote calculates the total votes received by each candi-
date. This method must access the arrays votesByRegion and totalVotes . This
method has two parameters: a parameter corresponding to the array
votesByRegion and a parameter corresponding to the array totalVotes . The
definition of this method is:
1
4
Search WWH ::




Custom Search