Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment you will write a Java program that uses arrays to create a simple bar chart scoreboard for a group of players. Create

image text in transcribedimage text in transcribed

For this assignment you will write a Java program that uses arrays to create a simple bar chart scoreboard for a group of players. Create a new project named BarChartScoreboard and create a new Java class in that project named BarChart Scoreboard.java in the default package. 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 - - - - - - - - - John Wagner **** ************************ Karen Berger **** ***************************************** Jo Duffy ************* If the user enters a 0 for the number of players, a goodbye message should be displayed instead: Enter the number of players: 0 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: numStars - ( score / maxScore ) * 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: 2 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 * *** * ** * * ** ** ** *** * ** ** *** * * * High Scorer *********** Low Scorer ** ** * * * * ***** 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 ) / maxScore 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 O. You can assume that values entered by the user for scores will be non-negative. In the case of scores of O, 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 Duffy For this assignment you will write a Java program that uses arrays to create a simple bar chart scoreboard for a group of players. Create a new project named BarChartScoreboard and create a new Java class in that project named BarChart Scoreboard.java in the default package. 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 - - - - - - - - - John Wagner **** ************************ Karen Berger **** ***************************************** Jo Duffy ************* If the user enters a 0 for the number of players, a goodbye message should be displayed instead: Enter the number of players: 0 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: numStars - ( score / maxScore ) * 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: 2 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 * *** * ** * * ** ** ** *** * ** ** *** * * * High Scorer *********** Low Scorer ** ** * * * * ***** 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 ) / maxScore 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 O. You can assume that values entered by the user for scores will be non-negative. In the case of scores of O, 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 Duffy

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

What are the HR forecasting techniques?

Answered: 1 week ago

Question

Define succession planning. Why is it important?

Answered: 1 week ago

Question

Distinguish between forecasting HR requirements and availability.

Answered: 1 week ago