The Huntington High School basketball team has five players named Art, Bob, Cal,
ID: 3807830 • Letter: T
Question
The Huntington High School basketball team has five players named Art, Bob, Cal, Dan, and Eli.
Accept the number of points scored by each player in a game and create a bar chart that illustrates the points scored, similar to the following output:
Enter points earned by Art >> 6
Enter points earned by Bob >> 3
Enter points earned by Cal >> 1
Enter points earned by Dan >> 7
Enter points earned by Eli >> 2
Points for Game
-----------------------------------------------------
Art ******
Bob ***
Cal *
Dan *******
Eli **
Save the file as BarChart.java.
Also create the application/project called BarGraphTest.java class that has the main method and an object in order to use the BarChart class.
Explanation / Answer
import java.util.Scanner;
/////////////////////////////////////// CLASS BarGraphTest /////////////////////////////////////////////
public class BarGraphTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BarChart barChart = new BarChart();
System.out.println("Enter points earned by Art >> ");
int pointArt = sc.nextInt();
System.out.println("Enter points earned by Bob >> ");
int pointBob = sc.nextInt();
System.out.println("Enter points earned by Cal >> ");
int pointCal = sc.nextInt();
System.out.println("Enter points earned by Dan >> ");
int pointDan = sc.nextInt();
System.out.println("Enter points earned by Eli >> ");
int pointEli = sc.nextInt();
sc.close();
System.out.println(" Points for Game ");
System.out.println("------------------------------------ ");
System.out.print("Art: "); barChart.drowBar(pointArt);
System.out.print("Bob: "); barChart.drowBar(pointBob);
System.out.print("Cal: "); barChart.drowBar(pointCal);
System.out.print("Dan: "); barChart.drowBar(pointDan);
System.out.print("Eli: "); barChart.drowBar(pointEli);
}
}
//////////////////////////////////////// CLASS BarChart //////////////////////////////////////
class BarChart{
public void drowBar(int points){
for(int i=0;i<points;i++){
System.out.print("*");
}
System.out.print(" ");
}
}
==============================OUTPUT===================================
Enter points earned by Art >> 6
Enter points earned by Bob >> 3
Enter points earned by Cal >> 1
Enter points earned by Dan >> 7
Enter points earned by Eli >> 2
Points for Game
------------------------------------
Art: ******
Bob: ***
Cal: *
Dan: *******
Eli: **
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.