Assignment 11.2: New Hampshire Primary (10 pts) - The New Hampshire Primary is taking place this Tuesday, February 11, 2020.
- According to Wikipedia, a primary "Primary elections or often just primaries, are the process by which voters can indicate their preference for their party's candidate, or a candidate in general, in an upcoming general election... with the goal of narrowing the field of candidates"
- The New Hampshire primary is the first of the primary elections, which will be held to select the Democratic nominee for the 2020 presidential race.
- Note that the Republican nominee has essentially already been determined
- Although New Hampshire is just a small state, its primary receives massive media coverage, and, therefore, has a greater influence over the Democratic race than is small size would suggest.
- In this assignment we will develop a program to count votes for the 2020 New Hampshire Primary.
- The user enters votes based on a simple menu that presents the candidates.
- The user then inputs a single character (upper or lowercase A-C) to choose their 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 file Primary.java.
- 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.
- 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 Run.
- Your program should also report an error message if the user enters a letter other than A-C or X, as shown below.
- When your program works identically to the example output below, submit it to Canvas.
Example Output: ***New Hampshire Primary Candidates!*** Candidate A: Bernie Sanders Candidate B: Elizabeth Warren Candidate C: Joe Biden Candidate D: Pete Buttigieg Enter your choice (A-D) or X to exit: C You chose candidate Joe Biden Candidate A: Bernie Sanders Candidate B: Elizabeth Warren Candidate C: Joe Biden Candidate D: Pete Buttigieg Enter your choice (A-D) or X to exit: b You chose candidate Elizabeth Warren Candidate A: Bernie Sanders Candidate B: Elizabeth Warren Candidate C: Joe Biden Candidate D: Pete Buttigieg Enter your choice (A-D) or X to exit: A You chose candidate Bernie Sanders Candidate A: Bernie Sanders Candidate B: Elizabeth Warren Candidate C: Joe Biden Candidate D: Pete Buttigieg Enter your choice (A-D) or X to exit: Z Invalid choice. Please enter A, B, C, or D. Candidate A: Bernie Sanders Candidate B: Elizabeth Warren Candidate C: Joe Biden Candidate D: Pete Buttigieg Enter your choice (A-D) or X to exit: a You chose candidate Bernie Sanders Candidate A: Bernie Sanders Candidate B: Elizabeth Warren Candidate C: Joe Biden Candidate D: Pete Buttigieg Enter your choice (A-D) or X to exit: D You chose candidate Pete Buttigieg Candidate A: Bernie Sanders Candidate B: Elizabeth Warren Candidate C: Joe Biden Candidate D: Pete Buttigieg Enter your choice (A-D) or X to exit: X ***Primary Results!*** Bernie Sanders: 2 Elizabeth Warren: 1 Joe Biden: 1 Pete Buttigieg: 1 |