Question

In: Computer Science

To do: Write a program names BarChartWhile that ask’s the user for today’s sales (to the...

To do: Write a program names BarChartWhile that ask’s the user for today’s sales (to the closest $100) at five stores. The program should display a bar chart comparing each store’s sales. Create each bar in the chart by displaying a row of asterisks. Each asterisk should represent $100 of sales. You must use a while loop to display the chart. Actually – you will need five while loops, one for each store. Those of you with some programming background, you CANNOT use arrays, etc. You must use separate variables for each store.

To do: Repeat the program above but name it BarChartFor and use five for loops. The output will look identical.

Java language.

Sample output:

Today's sales for store 1 (rounded to the nearest 100)

300

Today's sales for store 2 (rounded to the nearest 100)

700

Today's sales for store 3 (rounded to the nearest 100)

1500

Today's sales for store 4 (rounded to the nearest 100)

2100

Today's sales for store 5 (rounded to the nearest 100)

200

SALES BAR CHART

Store 1 - Sales = 300:***

Store 2 - Sales = 700:*******

Store 3 - Sales = 1500:***************

Store 4 - Sales = 2100:*********************

Store 5 - Sales = 200:**

Solutions

Expert Solution

1.

import java.util.Scanner;

class BarChartWhile
{
   public static void main (String[] args)
   {
       Scanner input = new Scanner(System.in);
      
      
           System.out.println("Today's sales for store 1 (rounded to the nearest 100)");
           int store1Sale = input.nextInt();
           System.out.println("Today's sales for store 2 (rounded to the nearest 100) ");
           int store2Sale = input.nextInt();
           System.out.println("Today's sales for store 3 (rounded to the nearest 100) ");
           int store3Sale = input.nextInt();
           System.out.println("Today's sales for store 4 (rounded to the nearest 100) ");
           int store4Sale = input.nextInt();
           System.out.println("Today's sales for store 5 (rounded to the nearest 100) ");
           int store5Sale = input.nextInt();
          
           System.out.println("SALES BAR CHART");
          
          
       int i = 0;
       System.out.print("Store 1 - Sales = "+store1Sale+":");
           while(i<store1Sale)
           {
           System.out.print("*");
           i = i+100;
           }
          
           System.out.println();
          
           i = 0;
       System.out.print("Store 2 - Sales = "+store2Sale+":");
           while(i<store2Sale)
           {
           System.out.print("*");
           i = i+100;
           }
          
           System.out.println();
          
           i = 0;
       System.out.print("Store 3 - Sales = "+store3Sale+":");
           while(i<store3Sale)
           {
           System.out.print("*");
           i = i+100;
           }
          
           System.out.println();
          
           i = 0;
       System.out.print("Store 4 - Sales = "+store4Sale+":");
           while(i<store4Sale)
           {
           System.out.print("*");
           i = i+100;
           }
           System.out.println();
          
          
           i = 0;
       System.out.print("Store 5 - Sales = "+store5Sale+":");
           while(i<store5Sale)
           {
           System.out.print("*");
           i = i+100;
           }
          
   }
}

Output:

Today's sales for store 1 (rounded to the nearest 100)
300
Today's sales for store 2 (rounded to the nearest 100) 
700
Today's sales for store 3 (rounded to the nearest 100) 
1500
Today's sales for store 4 (rounded to the nearest 100) 
2100
Today's sales for store 5 (rounded to the nearest 100) 
200
SALES BAR CHART
Store 1 - Sales = 300:***
Store 2 - Sales = 700:*******
Store 3 - Sales = 1500:***************
Store 4 - Sales = 2100:*********************
Store 5 - Sales = 200:**

2.

import java.util.Scanner;

class BarChartFor
{
   public static void main (String[] args)
   {
       Scanner input = new Scanner(System.in);
      
      
           System.out.println("Today's sales for store 1 (rounded to the nearest 100)");
           int store1Sale = input.nextInt();
           System.out.println("Today's sales for store 2 (rounded to the nearest 100) ");
           int store2Sale = input.nextInt();
           System.out.println("Today's sales for store 3 (rounded to the nearest 100) ");
           int store3Sale = input.nextInt();
           System.out.println("Today's sales for store 4 (rounded to the nearest 100) ");
           int store4Sale = input.nextInt();
           System.out.println("Today's sales for store 5 (rounded to the nearest 100) ");
           int store5Sale = input.nextInt();
          
           System.out.println("SALES BAR CHART");
          
          
      
       System.out.print("Store 1 - Sales = "+store1Sale+":");
           for(int i=0;i<store1Sale;i=i+100)
           {
           System.out.print("*");
          
           }
          
           System.out.println();
          
      
       System.out.print("Store 2 - Sales = "+store2Sale+":");
           for(int i=0;i<store2Sale;i= i+100)
           {
           System.out.print("*");
      
           }
          
           System.out.println();
          
      
       System.out.print("Store 3 - Sales = "+store3Sale+":");
           for(int i=0;i<store3Sale;i=i+100)
           {
           System.out.print("*");
          
           }
          
           System.out.println();
          
      
       System.out.print("Store 4 - Sales = "+store4Sale+":");
           for(int i=0;i<store5Sale;i=i+100)
           {
           System.out.print("*");
      
           }
           System.out.println();
          
          
          
       System.out.print("Store 5 - Sales = "+store5Sale+":");
           for(int i=0;i<store5Sale;i = i+100)
           {
           System.out.print("*");
          
           }
          
   }
}

Output:

Today's sales for store 1 (rounded to the nearest 100)
300
Today's sales for store 2 (rounded to the nearest 100) 
700
Today's sales for store 3 (rounded to the nearest 100) 
1500
Today's sales for store 4 (rounded to the nearest 100) 
2100
Today's sales for store 5 (rounded to the nearest 100) 
200
SALES BAR CHART
Store 1 - Sales = 300:***
Store 2 - Sales = 700:*******
Store 3 - Sales = 1500:***************
Store 4 - Sales = 2100:*********************
Store 5 - Sales = 200:**

Do ask if any doubt. Please up-vote.


Related Solutions

Write a Java program to do the following: Ask the user to enter 10 first names...
Write a Java program to do the following: Ask the user to enter 10 first names (one word - no hyphen or apostrophe) using the keyboard. 1) Display the list of names one per line on the Console. 2) Display the names again, after eliminating duplicates using a HashSet (Your code MUST use HashSet).
Write a JAVA program that prompts the user for the number of names they’d like to...
Write a JAVA program that prompts the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Write a program called listful.py, in which the user inputs names, which get added to a...
Write a program called listful.py, in which the user inputs names, which get added to a list. Your program should: · Include a comment in the first line with your name. · Include comments describing each major section of code. · Create a list. · Ask the user to input a first name or hit enter to end the list. · If the user adds a first name (i.e., anything other than a blank value): o Add the name to...
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names     &
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close Do you...
Please code C# 10. Write a program that allows a user to input names and corresponding...
Please code C# 10. Write a program that allows a user to input names and corresponding heights (assumed to be in inches). The user can enter an indefinite number of names and heights. After each entry, prompt the user whether they want to continue. If the user enters true, ask for the next name and height. If the user enters false, display the name of the tallest individual and their height. Sample run: “Name?” James “Height?” 50 “Continue?” True “Name?”...
Write a C++ program using dynamic arrays that allows the user to enter the last names...
Write a C++ program using dynamic arrays that allows the user to enter the last names of the candidates in a local election and the number of votes received by each candidate. The program must ask the user for the number of candidates and then create the appropriate arrays to hold the data. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
Write a program that will read user input, and do the following: 1. The user can...
Write a program that will read user input, and do the following: 1. The user can input letters [A-Z] as much as he wants (ignore case). 2. If the user input other than letters or two characters, stop the input process and start to print unduplicated sorted pairs such as the below examples: User input: A a e b d d D E a B 1 Output: AB AD AE BD BE DE User Input: a q w e dd...
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT