Problem 29: Election day
It’s almost election day and the election officials need a program to help tally
election results. There are two candidates for office—Polly Tichen and Ernest
Orator. The program’s job is to take as input the number of votes each candidate
received in each voting precinct and find the total number of votes for each. The
program should print out the final tally for each candidate—both the total
number of votes each received and the percent of votes each received. Clearly
a loop is needed. Each iteration of the loop is responsible for reading in the votes
from a single precinct and updating the tallies. A skeleton of the program is in
the file Election.java. Open a copy of the program in your text editor and do the
following.
1. The election officials want more information. They want to know how many
precincts each candidate carried (won). Add code to compute and print this. You
need three new variables: one to count the number of precincts won by Polly,
one to count the number won by Ernest, and one to count the number of ties.
Test your program after adding this code.
Election day
Share
2 Answers