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

Write a program that asks the user to enter todays sales for five stores. The pr

ID: 3641578 • Letter: W

Question

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

Enter todays sales for stores 1: 1000
Enter todays sales for stores 2: 1200
Enter todays sales for stores 3: 1800
Enter todays sales for stores 4: 800
Enter todays sales for stores 5: 1900

Sales Bar Chart
Store 1: **********
Store 2: ************
Store 3: ******************
Store 4: ********
Store 5: *******************

You must use a variation of methods (print(), println(), or printf().) to print the asterisks. Structure your print statements so that only one asterisk is printed at once so use loops to control how many asterisks are printed on a given line.

Thank You

Explanation / Answer

import java.util.Scanner;

public class SalesGraph {

       public static void main(String[] args) {

              int sales1, sales2, sales3, sales4, sales5;

              Scanner in = new Scanner(System.in);

              System.out.print("Enter today’s sales for stores 1: ");

              sales1 = in.nextInt();

              System.out.print("Enter today’s sales for stores 2: ");

              sales2 = in.nextInt();

              System.out.print("Enter today’s sales for stores 3: ");

              sales3 = in.nextInt();

              System.out.print("Enter today’s sales for stores 4: ");

              sales4 = in.nextInt();

              System.out.print("Enter today’s sales for stores 5: ");

              sales5 = in.nextInt();

              System.out.println();

              System.out.println("Sales Bar Chart");

              for(int i = 1; i < 6; ++i) {

                     System.out.printf("Store %d: ", i);

                     if(i == 1) {

                           bar(sales1);

                     }

                     if(i == 2) {

                           bar(sales2);

                     }

                     if(i == 3) {

                           bar(sales3);

                     }

                     if(i == 4) {

                           bar(sales4);

                     }

                     if(i == 5) {

                           bar(sales5);

                     }

              }

       }

       public static void bar(int n) {

              for(int i = 0; i < n / 100; ++i) {

                     System.out.print("*");

              }

              System.out.println();

       }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote