Fundamental Programming Concepts
Summer 2000

Lab 7

Overview

This lab requires the use of single-dimensional arrays.

 

Part I: VoteCounter
Create an electronic vote counter. Each candidate in the election will be identified simply by a number (1, 2, 3...). As input, the user should be able to enter the number of votes each candidate received. The output will consist of:
  • The total number of votes cast in the election
  • The average number of votes received by candidates
  • The number of candidates who received more than the average number of votes
  • A table showing, for each candidate, the candidate's number, the number of votes received, and percentage of the total votes received
  • The winner of the election and number of votes received by the winner
  • The runner-up in the election and number of votes received by the runner-up

Some additional requirements:

  • The maximum number of candidates in this election is ten, and the minimum is two. Use one of the techniques discussed in class for obtaining a variable number of input values from the user (a sentinel value, or prompting the user to enter the number of candidates first).
  • You should validate all input appropriately.
  • The table must be printed by a separate method, which has at least one parameter that is an array. Make use of other methods as appropriate (i.e., performing repeated tasks).
  • The percentage of the total vote should be rounded to two decimal places and be followed with a percent sign (e.g., 34.59%, 75.1%, etc.). You can accomplish this with a DecimalFormat object (LL p. 90).
  • Ignore the possibility of ties.
  • I will not give you an algorithm for determining the runner-up; you must solve that problem on your own. 

 

Submitting

You should submit exactly the following:

  • Lab7
    • VoteCounter.java