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

I need help writing this program in java, it has to look exactly like the sample

ID: 3863871 • Letter: I

Question

I need help writing this program in java, it has to look exactly like the sample output

Write a program to do the following:

Ask the user to enter the total sales for a chain of stores that you own. The number of stores will vary for each user input

Display the total sales in a bar graph for each store.

The graph should use asterisks with each asterisk representing $100 of a sale.

Input Validation:

The input must be evenly divisible by 100

Requirements:

The output must match exactly mine.

The graphs must be dynamically generated based on the user input.

You must use (for) loops to solve the problem you are NOT allowed to use arrays.

HINT: You will need nested loops for this one and will need to think creatively of how to use a string accumulator.

Sample Execution:

Explanation / Answer

BarGraph.java

import java.util.ArrayList;
import java.util.Scanner;

public class BarGraph {

   public static void main(String[] args) {
       //Creating array List
       ArrayList<Integer> al = new ArrayList<Integer>();
      
       //Declaring variables
       final int SENTINAL = -1;
       int sales = 0;
       int k = 0;

       // Scanner object is used to get the inputs entered by the user
       Scanner sc = new Scanner(System.in);

       //Getting the sales value emntered by the user
       System.out.print("Enter the total sales for Store (-1 to exit)" + (k + 1)+":");
       sales = sc.nextInt();  
       while (sales != SENTINAL) {
              
//If the sales value is not multiple of 100 display error message
           if (sales % 100 != 0) {
               System.out.println("** Invalid.Sales vaue must be multiple of 100 **");
           } else {
               al.add(sales);
               k++;
          
           }
           //getting the sales value entered by the user
           System.out.print("Enter the total sales for Store (-1 to exit)" + (k + 1)+":");
           sales = sc.nextInt();
       }
      
       //Displaying the report
       System.out.println("GRAPH OF TOTAL SALES");
       for(int i=0;i<al.size();i++)
       {
           System.out.print("Store "+(i+1)+":");
           for(int j=0;j<al.get(i);j+=100)
           {
               System.out.print("*");
           }
           System.out.println();
       }

   }

}

________________

Output:

Enter the total sales for Store 1:150
** Invalid.Sales vaue must be multiple of 100 **
Enter the total sales for Store 1:1000
Enter the total sales for Store 2:1200
Enter the total sales for Store 3:1800
Enter the total sales for Store 4:800
Enter the total sales for Store 5:1900
Enter the total sales for Store 6:-1
GRAPH OF TOTAL SALES
Store 1:**********
Store 2:************
Store 3:******************
Store 4:********
Store 5:*******************

_____________Thank You