Problem Description

You are going to write a program that repeatedly obtains the scores of five players in a game until a sentinel value is entered. The program will then compute some statistics on the scores and display a summary.

Input: The program will prompt the user to enter the number of the player or the sentinel value. If the number is a valid player number (between 1 and 5), then the program will prompt the user to enter the number of points the player earned (an integer). Points must be 0 or positive. You may assume the user enters the correct data type at each prompt, but you may not assume that the data falls within a meaningful range (is not negative). Your program must validate the inputs.

Output: After the user has finished entering data and has entered the sentinel value, if any valid data was entered, then the program will display the total number of points scored by all players (as it is a cooperative game and the players represent a team), the highest scoring player (in the event of a tie, you may choose which highest scoring player is shown), and a summary table composed of the player number, points earned by the player, and percentage of team points earned by that player (the table will always display all players, regardless of whether they scored points). Percentages will show two decimal places.

Interface: Use the following prompts and output messages (exactly, except for values that should be substituted in, such as player number, points, and percentages, which are underlined):

Which player? (1, 2, 3, 4, or 5; -1 to quit):
How many points did player 1 score?
Team Total 600
High Score 200
Star Player Player 5
Player Points % of Total
1 100 16.67

Use the following error messages for invalid input or no input:

That is not a valid player number.
That is an invalid score.
No scores were entered.

If the user enters a bad player number, they should see the Which player? prompt again. If they enter a bad score, you may either prompt for the score until they give a valid score, or prompt for the player number again. The sample solution is programmed to repeatedly prompt for the player score until a valid score is given.

Once the user has entered the sentinel value, if there is at least one valid non-zero count, the team total, high score, star player, and summary information should be calculated and the summary information should be displayed in a table like the following (substitute actual data and calculated results):

Player Points % of Total
1 100 25.00
2 100 25.00
3 0 0.00
4 200 50.00
5 0 0.00

The column width for the for the player column is 15 characters, the column width for the other two columns is 20 characters, and the percentage should be displayed to two decimal places.

If there are no valid non-zero counts, the program should display the following message:

No scores were entered.

Design specifications:

Use only techniques that are covered in the first three lessons. Use console input and output.

You must write a sentinel-controlled loop to obtain player data, with a sentinel value of -1.

Do not, under any circumstances, use JOptionPane, System.exit, return, continue, or any other command that breaks out of a block of code. Use break only in switch statements. Do not submit code that includes these constructs (except for break in switch statements). Submit whatever you can write that does not include these constructs.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.