-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBarChart.java
More file actions
75 lines (57 loc) · 1.6 KB
/
Copy pathBarChart.java
File metadata and controls
75 lines (57 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.*;
/**@author Lemuel M. Uhuru
* @Date July 15, 2013
* Book Title: From Control Structures through Objects by Tony Gaddis
* Page: 269 Challenge 12: Bar Chart
*
* @Description Write a program that asks the user to enter today's
* sales for five stores. The program should display a bar chart comparing
* each store's sales. Create each bar in the bar chart by displaying a row
* of asterisks. Each asterisk should represent $100 of sales.
*/
public class BarChart {
public static void main(String[] args) {
// Create Scanner object
Scanner input = new Scanner(System.in);
// Store sales
int sales = 0;
System.out.print("Enter today's sales for store 1: ");
int sales1 = input.nextInt();
System.out.print("Enter today's sales for store 2: ");
int sales2 = input.nextInt();
System.out.print("Enter today's sales for store 3: ");
int sales3 = input.nextInt();
System.out.print("Enter today's sales for store 4: ");
int sales4 = input.nextInt();
System.out.print("Enter today's sales for store 5: ");
int sales5 = input.nextInt();
// Newline
System.out.println("");
// Table Header
System.out.println("SALES BAR CHART");
for(int k = 1; k <= 5; k++){
System.out.print("Store " + k + ": ");
switch(k){
case 1:
sales = sales1;
break;
case 2:
sales = sales2;
break;
case 3:
sales = sales3;
break;
case 4:
sales = sales4;
break;
case 5:
sales = sales5;
}
for(int l=1; l<=sales/100; l++){
System.out.print("*");
}
// Newline
System.out.println("");
}
}
}