Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

need help for a Java project, it's so difficult This program will ask the user to enter a number of players, then ask the user

need help for a Java project, it's so difficult

image text in transcribedimage text in transcribed

This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the user are shown in BOLD and that the output should end with a new line Enter the number of players: 3 Enter a player name: John Wagner Enter the score for John Wagner: 33 Enter a player name: Karen Berger Enter the score for Karen Berger: 55 Enter a player name: Jo Duffy Enter the score for Jo Duffy: 15 Current Scoreboard Karen Berger Jo Duftf x**x* If the user enters a O for the number of players, a goodbye message should be displayed instead Enter the number of players: e No players to display? Goodbye! Storing the input You will need to create two arrays to store the data - one to hold player names and one to hold scores. The arrays will be what is known as parallel arrays-two values with the same index will be linked to each other. For example, given the transcript above, the array holding names would have the values ["John Wagner", "Karen Berger", "Jo Duffy"] and the array holding scores would have the values 33, 55,15] Once you have read the values into the two arrays, you can worry about formatting the output. Formatting the output The length of the bar for the player with the highest score must be 50 stars. The length of the bars for the other players is determined by using a proportion of their score to the maximum score nums tars = ( score / maxscre ) * 50 For example, if the highest score is 10 and another player has a score of 8, then the length of the second player's bar will be (8/10)50 or 40 stars Enter the number of players: Enter a player name: High Scorer Enter the score for High Scorer: 10 Enter a player name: Low Scorer Enter the score for Low Scorer: 8 Current Scoreboard NOTE: Remember that if you want to use fractions in Java you have to do some extra work. You can look back at how you computed the percentage in the guess a number project for one way to solve this. Another way to solve it is to recognize that the above equation can be rewritten using a little bit of algebra as numStars ( score * 50 ) / maxscre If you do that, you don't have to convert values from int to double and back at all. In general in Java if you don't have to convert between int and double types it is better not to. NOTE 2: Notice that the bars all line up on the left hand side, with a single space after the longest name that the user entered. There are a number of ways to solve this problem - one way to do it is to use a loop to append spaces to the end of the shorter names to "pad them out to the right length. An algorithm to do this might be 1. Determine the string with the longest length, call it max 2. Start with a variable pos 0 3. With the name stored at index pos, loop to append spaces until its length is the same as the length of max. 4. Increment pos by 1 5. Repeat steps 3 and 4 until all of the strings are the same length NOTE 3: Your solution must be able to handle names of length 0 and scores of 0. You can assume that values entered by the user for scores will be non-negative. In the case of scores of 0, no stars should be printed - be careful of division by zero errors when determining your proportions! In the case of names of length 0, no name will be printed but the bar may be An example where the player name is left blank would be: Enter the number of players: 1 Enter a player name: Enter the score for 10 Current Scoreboard And an example where the player score is set to 0 (and the max score is also zero): Enter the number of players:1 Enter a player name: Jo Duffy Enter the score for Jo Duffy: 0 Current Scoreboard Jo Duff

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_2

Step: 3

blur-text-image_3

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students explore these related Databases questions