Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A. The Huntington High School basketball team has five players named Art, Bob, Cal, Dan, and Eli. Accept the number of points scored by each

A. 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 by displaying an asterisk for each point. The output looks similar to the chart in Figure 6-34.

B.Modify the BarChart program to accept the number of points scored by each player in a season. The bar chart displays one asterisk for each 10 points scored by a player. For example, if a player has scored 48 points, then display four asterisks.

This is my code for part A which is correct I just need help with part B..

Part A code:

import java.util.Scanner;

class BarChart { //Main method public static void main(String args[]) { //Array of names String[] playerNames = {"Art", "Bob", "Cal", "Dan", "Eli"}; //Array for storing points int[] points = new int[5]; int i, j; //Scanner class objects Scanner sc = new Scanner(System.in); //Reading points scored for(i=0; i<5; i++) { //Prompting and accepting points scored by each player System.out.print(" Enter points scored by " + playerNames[i] + " >> "); points[i] = sc.nextInt(); } System.out.println(" Points for Game "); //Printing bar chart for(i=0; i<5; i++) { //Printing player name System.out.print(" " + playerNames[i] + " "); //Generating stars for(j=1; j<=points[i]; j++) { System.out.print("*"); } } System.out.println(" "); } }

Given code for B:

import java.util.Scanner;

public class BarChart2 {

public static void main (String[] args) {

Scanner input = new Scanner(System.in);

int artPoints;

int bobPoints;

int calPoints;

int danPoints;

int eliPoints;

final int AMT_EACH_ASTERISK = 10;

System.out.println("Enterpoints earned for the season");

System.out.print(" by Art >> ");

artPoints = input.nextInt();

System.out.print(" by Bob >> ");

bobPoints = input.nextInt();

System.out.print(" by Cal >> ");

calPoints = input.nextInt();

System.out.print(" by Dan >> ");

danPoints = input.nextInt();

System.out.print(" by Eli >> ");

eliPoints = input.nextInt();

System.out.println(" Points for Season (each asterisk represents " +

AMT_EACH_ASTERISK + " points) ");

// Write your code here to draw the charts

}

public static void drawChart(String name, int points, int amt_each) {

// Write your code here

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions