CS139 Algorithm Development


Software Requirements Specification

Programming Assignment 5 - OPTIONAL

Voting Booth

Due No Later Than Thursday, Dec 16 by noon


Introduction

Purpose: This application will simulate a simple voting booth. This PA is optional and may take the place of a bad grade in PAs 1-4. It may not substitute for PA6.

Objectives - At the conclusion of this exercise the student will demonstrate that they can: Deadlines

Prerequisites

You should be familiar with the material about classes from Gaddis, chapters 6 and 9.

Starter files

Vote.java - Represents the votes received from a VotingBooth.
VotingBooth.java - Uses Vote to keep track of the voting.

Vote.java - Changes you must make in this file.

  1. Create four private attributes.  You should not add any other attributes to this file.
  2. Create a constructor that initializes each of the attributes.
  3. Create a public mutator method, voteAllen, which takes in no parameters and returns nothing.
  4. Create a public mutator method, voteWebb, which takes in no parameters and returns nothing.
  5. Create a public mutator method, voteOther, which takes in a String parameter and returns nothing.
  6. Create a public accessor method, toString, which takes in no parameters and returns a String - NOTE, this is already be built in your template.
        Allen: 3
    Webb: 4
    Other: 2

    Mickey Mouse, James Madison

VotingBooth.java

  1. Declare your Vote object and any other variables you need.
  2. Instantiate your Vote object.
  3. Create a prompt using the String, "Enter a for Allen, w for Webb, o for other, x to exit: "
  4. Read in the value entered.
  5. Output the newline character after reading in the value.
  6. If an x is entered, output a newline character, then display the results ov the election(call the Vote object's toString method) and terminate the program.
  7. For all other values, do the following:

    a - call the voteAllen method using your Vote object.
    w - call the voteWebb method using your Vote object.
    o - Prompt for the name of the "write-in" candidate, using the String, "Enter the name: ". Read that value and pass it to the voteOther method using your Vote object.
    anything other than x, a, w, o - reenter the prompt and reread the result.

  8. Reprompt for the vote and read in the corresponding entry.
  9. NOTE: There should only be one blank line when run interactively between the prompts.

Written 11/28/2010 (nlh)