-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.java
More file actions
71 lines (54 loc) · 1.74 KB
/
Timer.java
File metadata and controls
71 lines (54 loc) · 1.74 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
import java.io.*;
import java.util.HashMap;
public class Timer {
static void printInventory(){
Inventory inv = Inventory.getInstance();
try {
PrintWriter out = new PrintWriter(new FileWriter("inventoryReport.txt"));
for (int i = 0; i < inv.names.size(); i++) {
out.printf("%s/%d/%.2f\n",
inv.names.get(i),
inv.amounts.get(i),
inv.prices.get(i));
}
out.close();
}
catch(IOException e){
}
}
static void printRevenue(){
TransactionHistory hist = TransactionHistory.getInstance();
try {
PrintWriter out = new PrintWriter(new FileWriter("dailyReport.txt"));
HashMap<String, Integer> map = prepareItemData();
for(String s : map.keySet()){
out.printf("%s sold: %d\n", s, map.get(s));
}
out.printf("Total revenue: $%.2f\n", prepareTotals());
out.close();
}
catch(IOException e){
}
}
static HashMap<String, Integer> prepareItemData(){
TransactionHistory hist = TransactionHistory.getInstance();
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(String item : hist.items){
if(map.containsKey(item)){
map.put(item, map.get(item) + 1);
}
else{
map.put(item, 1);
}
}
return map;
}
static float prepareTotals(){
TransactionHistory hist = TransactionHistory.getInstance();
float total = 0;
for(Float f : hist.totals){
total += f;
}
return total;
}
}