I am working on this exercise now and am having some trouble with it. Did you get it figured out? I got my input from the user fine and display the graph afterwards, however the graph shows the total for all five stores on every line. I tried changing my counter variable name in each for loop but that didn't help. Here is my code:
import java.util.Scanner; // Have to import in order to use the Scanner class.
// This is my program.
public class barChart
{
public static void main (String[] args)
{
int storeNum; //to hold a place for Store counter.
int sales1;
int sales2;
int sales3;
int sales4;
int sales5;
// This creates a scanner object to read user input.
Scanner keyboard = new Scanner(System.in);
System.out.print("What is today's sales for store1? "); //Get sale totals from user
sales1 = keyboard.nextInt(); //Place the input from the user in the store1 variable.
System.out.print("What is today's sales for store2? "); //Get sale totals from user
sales2 = keyboard.nextInt(); //Place the input from the user in the store2 variable.
System.out.print("What is today's sales for store3? "); //Get sale totals from user
sales3 = keyboard.nextInt(); //Place the input from the user in the store3 variable.
System.out.print("What is today's sales for store4? "); //Get sale totals from user
sales4 = keyboard.nextInt(); //Place the input from the user in the store4 variable.
System.out.print("What is today's sales for store5? "); //Get sale totals from user
sales5 = keyboard.nextInt(); //Place the input from the user in the store5 variable.
System.out.println();
// Create a header for the table.
System.out.println("Sales Bar Chart");
System.out.println("---------------------");
for (storeNum = 1; storeNum<=5; storeNum++)
{
//System.out.print("What is today's sales for store " + storeNum + "?: "); //Get sale totals from user
//sales = keyboard.nextInt(); //Place the input from the user in the store1 variable.
//Display Store number
System.out.print("Store " + storeNum);
for (int count = 0; count<sales1; count+=100)
{
//Display sales in hundreds
System.out.print("*");
}
for (int count1 = 0; count1<sales2; count1+=100)
{
//Display sales in hundreds
System.out.print("*");
}
for (int count2 = 0; count2<sales3; count2+=100)
{
//Display sales in hundreds
System.out.print("*");
}
for (int count3 = 0; count3<sales4; count3+=100)
{
//Display sales in hundreds
System.out.print("*");
}
for (int count4 = 0; count4<sales5; count4+=100)
{
//Display sales in hundreds
System.out.print("*");
}
System.out.println();
}
}
}