Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

More Books

Students also viewed these Databases questions

Question

=+8. Will the merger or acquisition affect specific competitors?

Answered: 1 week ago