Assignment 10

Due Tuesday, May 19 at 11:59pm on Canvas


Important: You must only use concepts and methods taught in class to complete these assignments - or you will receive a 0.


Pair Programming (Required - Or You will Receive a 0)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your Lab code to Canvas.
  • Please make sure both your names are on your file (hint: use a comment).
  • If you need help finding a partner, please contact me as soon as possible.

Assignment 10: 2020 Election (10 pts)

  • In this assignment we will develop a program to count votes for the 2020 Presidential election scheduled for November 3, 2020.
  • The user enters votes based on a simple menu that presents the candidates. 
  • For the purposes of this assignment, you should invent the candidates running for president.
  • Present a list of candidates to the user and allow her to enter a single character as input, and no other input, as shown in the Example Output.
    • The user will input a single character (upper or lowercase A-C) to choose her candidate from the menu.
  • Entering an 'X' (without the quotes) will exit the tallying operation and present a summary of the votes.
  • Write your code inside the a file Presidential.java
  • Use an indefinite while loop to allow multiple votes to be cast on your voting machine.
  • After all the votes are entered and the user enters an 'X', exit the loop and report the vote count by candidate names and neatly aligned as shown in the Example Output below.
  • Your program should also report an error message if the user enters a letter other than A-C or X, as shown.
  • When your program works identically to the example output (except the candidates are left up to your own choice), submit it to Canvas.

Example Output:

***2020 Presidential Election!***

Candidate A: Wonder Woman
Candidate B: Martin Luther King, Jr
Candidate C: Bruce Lee

Enter your choice (A-C) or X to exit: C
You chose candidate Bruce Lee

Candidate A: Wonder Woman
Candidate B: Martin Luther King, Jr
Candidate C: Bruce Lee


Enter your choice (A-C) or X to exit: b
You chose candidate Martin Luther King, Jr

Candidate A: Wonder Woman
Candidate B: Martin Luther King, Jr
Candidate C: Bruce Lee


Enter your choice (A-C) or X to exit: B
You chose candidate Martin Luther King, Jr

Candidate A: Wonder Woman
Candidate B: Martin Luther King, Jr
Candidate C: Bruce Lee

Enter your choice (A-C) or X to exit: Z
Invalid choice. Please enter A, B, C, or X.


Candidate A: Wonder Woman
Candidate B: Martin Luther King, Jr
Candidate C: Bruce Lee

Enter your choice (A-C) or X to exit: a
You chose candidate
Wonder Woman

Candidate A: Wonder Woman
Candidate B: Martin Luther King, Jr
Candidate C: Bruce Lee

Enter your choice (A-C) or X to exit: C
You chose candidate
Bruce Lee

Candidate A: Wonder Woman
Candidate B: Martin Luther King, Jr
Candidate C: Bruce Lee

Enter your choice (A-C) or X to exit: X

***Results!***
Wonder Woman: 1
Martin Luther King Jr: 2
Bruce Lee: 2