Question

Java

BasketBall Bar Chart Write a program that allows you to create a bar chart for the active members of a basketball team during

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I am sending code, screens of code and outputs. Refer the screens for better understanding. if any queries comment below. Thank you.

Code:

import java.util.*;
public class BarChart
{
   static void chart(String name,int points)
   {
       String star= "";//empty string.
       for(int i=0;i<points;i++)//adding points number of stars.
           star=star+"*";
       String s = String.format("%s\t%s",name,star);//printing name and stars.
       System.out.print(s+"\n");
   }
   public static void main(String args[])
   {
       Scanner sc = new Scanner(System.in);
       String names[] = new String[5];
       int points[] = new int[5];
       System.out.print("Enter the first names of the 5 players: ");
       for(int i=0;i<5;i++)//reading first names of 5 players.
           names[i] = sc.next();
       int i=0;
       do
       {
           System.out.print("Enter pointer earned by "+names[i]+": ");//reading the points of each player.
           points[i] = sc.nextInt();
           if(points[i] < 0)//if entered points is negative
           {
               while(true)//asking the user again and again till enter correct points.
               {
                   System.out.print("Invalid points. Please enter correct points of "+names[i]+": ");//reading points
                   points[i] = sc.nextInt();
                   if(points[i] >= 0)//entered correct points then stop the infinity loop.
                       break;
               }  
           }
           i++;
       }while(i<5);//condition
       System.out.print("\nPoints for Game\n\n");
       for(i=0;i<5;i++)
       {
           chart(names[i],points[i]);//passing the name and points of each player.
       }
   }
}

import java.util.*; public class BarChart static void chart (String name, int points) String star= ;//empty string. for(intpoints[i] = sc.nextInt (); if (points[i] >= 0)//entered correct points then stop the infinity loop. break; i++; }while (i<5);<terminated> BarChart [Java Application] C:\Program Files\ava\jre8\bin\javaw.exe (Oct 24, 2019 6:24:05 PM) Enter the first na<terminated> BarChart [Java Application] C:\Program Files\ava\jre8\bin\javaw.exe (Oct 24, 2019 6:28:51 PM) Enter the first na

Add a comment
Know the answer?
Add Answer to:
Java BasketBall Bar Chart Write a program that allows you to create a bar chart for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember...

    Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember the rules: 1. Rock beats scissors 2. Scissors beats paper 3. Paper beats rock The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an...

  • Use Java language to create this program Write a program that allows two players to play...

    Use Java language to create this program Write a program that allows two players to play a game of tic-tac-toe. Using a two-dimensional array with three rows and three columns as the game board. Each element of the array should be initialized with a number from 1 - 9 (like below): 1 2 3 4 5 6 7 8 9 The program should run a loop that Displays the contents of the board array allows player 1 to select the...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • C++ Language Overview: Design an APP for a basketball team with a unique name. There should be at least 10 players. The member variables required include team member’s names, jersey number, position p...

    C++ Language Overview: Design an APP for a basketball team with a unique name. There should be at least 10 players. The member variables required include team member’s names, jersey number, position played, and at least 3 stats. Positions are small forward, power forward, center, shooting guard and point guard. 1. A.) Design a class with member variables and appropriate member functions Data should be stored in a read/write file consisting of team member’s names, jersey number, position played, and...

  • Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players...

    Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...

  • Create a Java program which asks the user how many names they want to enter. The...

    Create a Java program which asks the user how many names they want to enter. The program should then instantiate an array that will hold this many names. The main method should call a method, getNames() to allow the user to enter the names. A for loop should be used in this method. Once the names are entered, the main method should call another method displayNames() which will use a while loop to display the names entered.

  • Using very basic Java programming Write a program that lets the user play the game of...

    Using very basic Java programming Write a program that lets the user play the game of Rock, Paper, Scissors against the computer.The program should use an array of Strings with the names of the choices.The program should loop until the human player decides to quit.The game should keep track of how many times the human won, lost, or tied and present those values when the game ends.

  • In Java Problem Description/Purpose:  Write a program that will compute and display the final score...

    In Java Problem Description/Purpose:  Write a program that will compute and display the final score of two teams in a baseball game. The number of innings in a baseball game is 9.    Your program should read the name of the teams. While the user does not enter the word done for the first team name, your program should read the second team name and then read the number of runs for each Inning for each team, calculate the...

  • In this project, you will use functions and dictionaries to track basketball players and their respective...

    In this project, you will use functions and dictionaries to track basketball players and their respective points, then display statistics of points made. You will need three functions as follows: def freeThrowMade(playerDictionary, playerName) - this function will add 1 point to the player's total score def twoPointMade(playerDictionary, playerName) - this function will add 2 points to the player's total score def threePointMade(playerDictionary, playerName) - this function will add 3 points to the player's total score Each of these functions has...

  • 18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use di...

    18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Write . Displays the contents of the board array. . Allows player 1 to select a location on the board for an X. The program should ask the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT