JAVA BEGINNER PROGRRAMMING Write a program that asks he user enter today\'s sale
ID: 3673105 • Letter: J
Question
JAVA BEGINNER PROGRRAMMING
Write a program that asks he user enter today's sales for five store. The program should display a bar chart comparing each store's sale. Create each bar in the bar chart to display a row of asterisks. Each asterisk should represent $100 of sales. Here is an example of program output:
Enter sales for Store 1: 1000
Enter sales for Store 2: 1200
Enter sales for Store 3: 1500
Enter sales for Store 4: 800
Enter sales for Store 5: 1900
SALES BAR CHART
Store 1: **********
Store 2: ************
Store 3: ***************
Store 4: ********
Store 5: *******************
For something extra - Change the scale on the fly to show an appropriate bar chart.
Explanation / Answer
import java.util.Scanner;
public class BarChart
{
public static void main(String[] args)
{
double[] store = new double[5];
Scanner userInput = new Scanner(System.in);
for(int i = 0; i < 5; i++)
{
System.out.printf("Enter today's sales for store %d: ", i + 1);
store[i] = userInput.nextDouble();
}
System.out.println(" SALES BAR CHART");
for(int i = 0; i < 5; i++)
{
System.out.printf("Store %d: ", i + 1);
for(int c = 0; c < store[i]/100; c++)
System.out.print("*");
System.out.println();
}
userInput.close();
}
}
OR
#include <iostream>
using namespace std;
int main()
{
int storesales[5];
int total = 0;
for (int i = 0; i <=4; i++)
{
cout <<" Store " << i + 1 << " sales : ";
cin >> storesales[i];
}
int AsteriskNumber[5];
for ( int x = 0; x<=4; x++)
{
AsteriskNumber[x] = storesales[x]/100;
cout <<" Store " << x+1 << ": " ;
do
{
cout << "*";
total= total + 1;
}
while(total<=AsteriskNumber[x]);
total = 0;
cout << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.