Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THIS HAS 2 PARTS 1) The Huntington High School basketball team has five players

ID: 3809818 • Letter: T

Question

THIS HAS 2 PARTS

1)

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.

2)

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

BarChart.java

import java.util.Scanner;


public class BarChart {
   String players[] = {"Art", "Bob", "Cal", "Dan", "Eli"};
   int scores[] = new int[5];
   public BarChart() {
      
   }
   public void readScores() {
   Scanner scan = new Scanner(System.in);
   for(int i=0; i<players.length; i++){
       System.out.print("Enter points earned by Art >> ");
       scores[i] = scan.nextInt();
   }
   }
   public void displayChart(){
       for(int i=0; i<players.length; i++){
           System.out.print(players[i]+" ");
           for(int j=0; j<scores[i]; j++){
               System.out.print("*");
           }
           System.out.println();
       }
      
   }
}

BarGraphTest.java


public class BarGraphTest {

  
   public static void main(String[] args) {
       BarChart b = new BarChart();
       b.readScores();
       b.displayChart();

   }

}

Output:

Enter points earned by Art >> 6
Enter points earned by Art >> 3
Enter points earned by Art >> 1
Enter points earned by Art >> 7
Enter points earned by Art >> 2
Art ******
Bob ***
Cal *
Dan *******
Eli **