-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecordKeeper.java
More file actions
173 lines (153 loc) · 6.54 KB
/
Copy pathRecordKeeper.java
File metadata and controls
173 lines (153 loc) · 6.54 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import java.util.ArrayList;
import java.util.*;
import java.io.*;
import java.text.*;
public class RecordKeeper {
private static final DecimalFormat form = new DecimalFormat("###,###,##0.00");
private static ArrayList<CartVirtualItem> restocks = new ArrayList<>();
private static ArrayList<CartVirtualItem> purchases = new ArrayList<>();
private static ArrayList<String> registryRecord = new ArrayList<>();
private static double dailyRevenue = 0.0;
private static int numOfTransactions;
/**
* adds a restock to the record
* (byte) type codes: 0 is book, 1 is CD, 2 is DVD
*
* @param byte type
* @param int index
* @param int numRestocked
*/
public static void addRestock(byte type, int index, int numRestocked) {
//the type, name, num restocked r to be saved in a CartVirtualItem
String itemName = Main.inventory.getName(type, index);
boolean found = false;
//if its found alrdy in the list then add the number of restocks to the current number
for (CartVirtualItem item : restocks) {
if (item.getType() == type && item.getName().equals(itemName)) {
//I don't have a mutator that adds so I just add the number to the previous number
item.setAmount(item.getAmount()+numRestocked);
found = true;
break;
}
}
//if it wasnt found then add it to the end of the list :D
//(alphabetical order doesn't matter, only the order of what was restocked first)
if (!found)
restocks.add(new CartVirtualItem(type, Main.inventory.getName(type, index), numRestocked, Main.inventory.isSpecial(type, index)));
}
/**
* adds a purchase to the record
* (byte) type codes: 0 is book, 1 is CD, 2 is DVD
*
* @param byte type
* @param int index
* @param int numBought
*/
public static void addPurchase(byte type, int index, int numBought) {
String itemName = Main.inventory.getName(type, index);
boolean found = false;
//if its found alrdy in the list then add the number of restocks to the current number
for (CartVirtualItem item : purchases) {
if (item.getType() == type && item.getName().equals(itemName)) {
//I don't have a mutator that adds so I just add the number to the previous number
item.setAmount(item.getAmount()+numBought);
found = true;
break;
}
}
//if it wasnt found then add it to the end of the list :D
//(alphabetical order doesn't matter, only the order of what was restocked first)
if (!found)
purchases.add(new CartVirtualItem(type, Main.inventory.getName(type, index), numBought, Main.inventory.isSpecial(type, index)));
dailyRevenue += ((Main.inventory.getPrice(type, index)+0.99)*numBought);
}
/**
* add to the record that a customer was registered
*
* @param String name
* @param int age
* @param String address
* @param boolean premium
*/
public static void addRegistered(String name, int age, String address, boolean premium) {
//if premium, add "premium" to the end
if (premium) registryRecord.add("Registered "+name+", "+age+", "+address+", premium");
//if not premium, add "nonpremium" to the end
else registryRecord.add("Registered "+name+", "+age+", "+address+", nonpremium");
}
/**
* add any custom message to the registry record
*
* @param String addThis
*/
public static void registryEdit(String addThis) {
registryRecord.add(addThis);
}
/**
* add money to the daily record of obtained cash
* yes even if the cash was obtained by selling customer data on the dark web
*
* @param double amt
*/
public static void addToDailyRevenue(double amt) {
dailyRevenue += amt;
}
/**
* adds one to the number of total transactions that day
*
*/
public static void addTransaction() {
numOfTransactions++;
}
/**
* write the report to the EndOfDayReport txt file
*
*/
public static void writeReport() {
try {
PrintWriter output = new PrintWriter(new FileOutputStream("EndOfDayReport.txt"));
output.println(" END OF DAY REPORT:\n\nINVENTORY\n Items Sold:");
//list the items sold (only if it's not empty)
if (purchases.isEmpty()) output.println("\tnone");
else for (CartVirtualItem item : purchases) {
switch(item.getType()) {
case 0: output.print("\t— Book, "); break;
case 1: output.print("\t— CD, "); break;
case 2: output.print("\t— DVD, "); break;
}
output.println(item.getName()+", "+item.getAmount()+", $"+form.format((Main.inventory.getPrice(item.getType(), Main.inventory.findIndex(item.getType(), item.getName()))+0.99)*item.getAmount()));
}
//the number of transactions now
output.println(" Total Number of Transactions: "+numOfTransactions+"\n");
//list the items stocked (only if it's not empty)
output.println(" Items Stocked:");
if (restocks.isEmpty()) output.println("\tnone");
else for (CartVirtualItem item : restocks) {
switch(item.getType()) {
case 0: output.print("\t— Book, "); break;
case 1: output.print("\t— CD, "); break;
case 2: output.print("\t— DVD, "); break;
}
output.println(item.getName()+", "+item.getAmount());
}
//print the registry info
output.println("\nREGISTRY:");
if (registryRecord.isEmpty()) output.println("\tnone");
else for (String printThing : registryRecord) {
output.println("\t— "+printThing);
}
//print the total revenue made during the day
output.println("\nTotal Revenue Today: $"+form.format(dailyRevenue));
output.close();
} catch (FileNotFoundException e) {
System.out.println("ono file gon");
}/* catch (IOException e) {
System.out.println("ono error ioexception\n"+e);
}*/
}
public static void printAll() {
for (CartVirtualItem bob : restocks) {
System.out.print(bob.getName()+" | ");
}
}
}