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...
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
Create a program that asks the user for the names of two car dealerships and the...
Create a program that asks the user for the names of two car dealerships and the # of cars sold in each one. Then output that data in two columns as shown below. The "Store location" column has a width of 25, while the "Cars sold" column has a width of 9. Also, notice the alignment of the second column. The program should end with the "Press Enter to end this program" prompt. OUTPUT Enter the location for the first...
what should this program do? Write a program (Lab8.cpp) that will ask the user for two...
what should this program do? Write a program (Lab8.cpp) that will ask the user for two file names. You will read the characters from each file and put them in separate queues. Then, you will read each character from each queue and compare it. If every character from both queues is the same, you will print “The files are identical.” Otherwise, you will print “The files are not identical.” Step-by-Step Instructions Create a character queue (named queue1) using the Standard...
Write an application that allows a user to enter the names and birthdates of up to...
Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names...
Write a program that: a.Asks the user for their first name.b.Asks the user for their...
Write a program that: a.Asks the user for their first name. b.Asks the user for their age. c.Asks the user for their last name. d.Print out to the user the following information: i.Number of characters in the first & last name combined ii.The full name all in upper case letters iii.The full name all in lower case letters iv.The first letter of the name v.The age Compile and test your code in NetBeans and then on Hackerrank at www.hackerrank.com/csc127-chapter2-classwork then...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT