Write a program that asks the user to enter today's sales for five stores. The program should display a bar chart comparing each store's sales. Create each bear in the bar chart by displaying a row of asterisks. Each asterisk should represent $100 of sales. Here is an example of the program's output.

Enter today's sales for store 1: 1000 [Enter]
Enter today's sales for store 2: 1200 [Enter]
Enter today's sales for store 3: 1800 [Enter]
Enter today's sales for store 4: 800  [Enter]
Enter today's sales for store 5: 1900 [Enter]

Sales Bar Chart

Store 1:
Store 2:
Store 3:
Store 4:
Store 5:

I can't seem to get my code to work. This is what I have so far

import javax.swing.JOptionPane;

public class BarChart
{
    public static void main(String[] args)
    {
        String inputOne = JOptionPane.showInputDialog("Enter today's sales " +
                "for store 1:  ");

        int storeOne = Integer.parseInt(inputOne);

        String inputTwo = JOptionPane.showInputDialog("Enter today's sales " +
                "for store :  ");

        int storeTwo = Integer.parseInt(inputTwo);

        String inputThree = JOptionPane.showInputDialog("Enter today's " +
                "sales for store 3:  ");

        int storeThree = Integer.parseInt(inputThree);

        String inputFour = JOptionPane.showInputDialog("Enter today's " +
                "sales for store 4:  ");

        int storeFour = Integer.parseInt(inputFour);

        String inputFive = JOptionPane.showInputDialog("Enter today's " +
                "sales for store 5:  ");

        int storeFive = Integer.parseInt(inputFive);

        JOptionPane.showMessageDialog(null, "\nSALES BAR CHART");

    }
}
        for (int count = 0; count <= barOne; count++)
        {
            JOptionPane.showMessageDialog(null, '*');
        }

1. Please post your code inside code tags in the future.
2. A bar chart is more useful when you can see all the bars together, so I think System.out.println makes more sense than showing one bar of output at a time using JOptionPane, unless you are required to display your output that way.
3. Whether you use JOptionPane or System.out, you should first create a string of "*" characters to display. You can use the loop you wrote, except you need to use storeOne instead of barOne to control the loop since that's the variable that has the value you need. Something like this:

String barOne = "";
for (int count = 0; count < storeOne; count++) {
   barOne += "*";
}
// then use barOne string to produce your output
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.