Java Reference
In-Depth Information
PROGRAMMING EXAMPLE: Election Results
The election for president of the student council of your local university is about to
be held. To ensure confidentiality, the election committee chair wants to computer-
ize the voting. The chair is looking for someone to write a program to process the
data and report the winner. Let's write a program to help the chair of the election
committee.
The university has four major colleges, and each college has several departments. For
election purposes, the four colleges are labeled Region 1, Region 2, Region 3, and
Region 4. Each department in each college holds its own voting and directly reports
the votes received by each candidate to the election committee. The voting is
reported in the form:
candidate_name region# number_of_votes_for_this_candidate
The election committee wants the output in the following tabular form:
--------------Election Results--------------
Candidate
Votes
Name
Region1 Region2 Region3 Region4
Total
----
------- ------- ------- -------
-----
Ashley
23
89
0
160
272
Danny
25
71
89
97
282
Donald
110
158
0
0
268
.
.
.
Winner: ???, Votes Received: ???
Total votes polled: ???
The names of the candidates in the output must be in alphabetical order.
For this program, we assume that six candidates are running for student council
president. This program can be enhanced to any number of candidates. Also, we
assume that no two candidates receive the same number of votes, that is, there is no
tie. We will leave it as an exercise for you to modify the program so that if more than
one candidate receives the maximum number of votes, then the program outputs the
names of all such candidates.
The data is provided in two files. One file, candData.txt , consists of the names of
the candidates. The names of the candidates in the file are in no particular order. In
the second file, voteData.txt , each line consists of the voting results in the
following form:
1
4
candidateName regionNumber numberOfVotesForTheCandidate
Search WWH ::




Custom Search