-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMV.java
392 lines (354 loc) · 12 KB
/
SMV.java
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package izza;
import java.io.IOException;
import java.util.Scanner;
public class SMV {
static hashMap hm;
static Cart c;
static coin c1;
static transaction tr;
public static void main(String[] args) throws IOException {
hm = new hashMap();
c = new Cart(8);
c1 = new coin(0);
tr = new transaction();
hm.put("Pikapoo", 20, 1.5);
hm.put("Hell and Sky", 20, 2.0);
hm.put("SkyJuicee", 20, 1.0);
hm.put("Popci", 20, 1.5);
hm.put("MAILO", 20, 2.5);
hm.put("99plus", 20, 1.5);
hm.put("Sepright", 20, 1.5);
hm.put("LeegalCaffeine", 20, 2.0);
user();
}
public static void user() throws IOException {
Scanner s = new Scanner(System.in);
System.out.println("Which one are you?"
+ "\n1) Vendor\n2) Buyer\nAnswer:");
String input = s.nextLine();
switch (input) {
case "1":
VendormainPage();
break;
case "2":
BuyermainPage();
break;
default:
System.out.println("Wrong entry, try again");
user();
}
}
public static void BuyermainPage() throws IOException {
double coin1;
Scanner s = new Scanner(System.in);
System.out.println("Welcome to buyer main page:"
+ "\n1: View catalog"
+ "\n2: Select drinks to add to cart"
+ "\n3: Select drinks to remove from your cart"
+ "\n4: to insert coins"
+ "\n5: to complete transaction"
+ "\n6: log out as a buyer");
String user = s.nextLine();
switch (user) {
case "1":
hm.display();
BuyermainPage();
break;
case "2":
addtocart();
break;
case "3":
RemoveFromCart();
break;
case "4":
coin1 = c1.getCoin();
c1.setCoin(insertCoin(coin1));
BuyermainPage();
break;
case "5":
transaction(total(c.arr, c.arr1), c1.getCoin());
break;
case "6":
user();
break;
default:
System.out.println("Wrong entry, try again");
BuyermainPage();
}
}
public static void addtocart() throws IOException {
Scanner s = new Scanner(System.in);
int d = 5;
do {
System.out.println("Enter the number of the drink you want to add");
hm.display();
System.out.println("[9] Back");
String input = s.nextLine();
switch (input) {
case "1":
c.addToCart("Pikapoo", 1);
c.display();
break;
case "2":
c.addToCart("Hell and Sky", 1);
c.display();
break;
case "3":
c.addToCart("SkyJuicee", 1);
c.display();
break;
case "4":
c.addToCart("Popci", 1);
c.display();
break;
case "5":
c.addToCart("MAILO", 1);
c.display();
break;
case "6":
c.addToCart("99plus", 1);
c.display();
break;
case "7":
c.addToCart("Sepright", 1);
c.display();
break;
case "8":
c.addToCart("LeegalCaffeine", 1);
c.display();
break;
case "9":
d = 6;
BuyermainPage();
default:
System.out.println("wrong entry, try again");
addtocart();
}
} while (d == 5);
}
public static void RemoveFromCart() throws IOException {
Scanner s = new Scanner(System.in);
int d = 5;
do {
System.out.println("Enter the number of the drink you want to remove or 9 to go back");
Cart.display();
String input = s.nextLine();
switch (input) {
case "1":
c.removeFromCart1(0);
c.display();
break;
case "2":
c.removeFromCart1(1);
c.display();
break;
case "3":
c.removeFromCart1(2);
c.display();
break;
case "4":
c.removeFromCart1(3);
c.display();
break;
case "5":
c.removeFromCart1(4);
c.display();
break;
case "6":
c.removeFromCart1(5);
c.display();
break;
case "7":
c.removeFromCart1(6);
c.display();
break;
case "8":
c.removeFromCart1(7);
c.display();
break;
case "9":
d = 6;
BuyermainPage();
default:
System.out.println("wrong entry, try again");
RemoveFromCart();
}
} while (d == 5);
}
public static double total(String[] arr, int[] arr1) {
double total = 0;
for (int i = 0; i < c.top; i++) {
total = total + (hm.get(arr[i]) * arr1[i]);
}
return total;
}
public static double insertCoin(double coins) throws IOException {
Scanner s = new Scanner(System.in);
int d = 5;
do {
System.out.println("Insert coins:"
+ "\n1: 10 cents"
+ "\n2: 25 cents"
+ "\n3: 50 cents"
+ "\n4: 1 Ringgit"
+ "\n5: 5 Ringgit"
+ "\n6: 10 Ringgit"
+ "\n7: Go back"
+ "\nCoins " + coins);
String input = s.nextLine();
switch (input) {
case "1":
coins = coins + 0.10;
break;
case "2":
coins = coins + 0.25;
break;
case "3":
coins = coins + 0.50;
break;
case "4":
coins = coins + 1;
break;
case "5":
coins = coins + 5;
break;
case "6":
coins = coins + 10;
break;
case "7":
d = 6;
System.out.println("You inserted " + coins + " MYR");
return coins;
default:
System.out.println("wrong entry try again");
insertCoin(coins);
}
} while (d == 5);
return coins;
}
public static void transaction(double total, double coins) throws IOException {
Scanner s = new Scanner(System.in);
System.out.println("Transaction menu"
+ "\nyou inserted " + coins
+ "\nyour total is " + total
+ "\nwould you like to proceed with your transaction?"
+ "\n1: Yes\n2: No\nPS: if your total is more than the money inserted the transaction will be aborted."
);
String input = s.nextLine();
switch (input) {
case "1":
if (coins >= total && total > 0) {
String log = "";
System.out.println("transation done");
String trans = tr.generateTrans();
log = log + "Time: " + tr.time1() + "\n";
log = log + "Transaction ID: " + trans + "\n";
System.out.println("You bought :");
log = log + c.display() + "\n";
tr.addlog(log);
System.out.println("Transaction ID: " + trans + "\ntime:"
+ tr.time1() + "\nThanks for buying from our vending machine!\n");
stockChanger(c.arr, c.arr1, c.top);
c.emptyCart();
c1.setCoin(coins - total);
if (coins - total != 0) {
System.out.println("your change is " + (coins - total) + "\n");
c1.setCoin(0);
}
user();
} else if (total == 0) {
System.out.println("Cart is empty");
BuyermainPage();
} else {
System.out.println("Your money is not enough, transaction will be aborted");
c1.setCoin(0);
c.emptyCart();
BuyermainPage();
}
break;
case "2":
System.out.println("transaction aborted, take your money back");
c1.setCoin(0);
c.emptyCart();
BuyermainPage();
default:
System.out.println("Wrong entry, try again");
BuyermainPage();
}
}
public static void stockChanger(String[] a, int[] b, int top) {
for (int i = 0; i < top; i++) {
hm.Stock(a[i], b[i]);
}
}
public static void VendormainPage() throws IOException {
Scanner s = new Scanner(System.in);
System.out.println("Welcome to vendor main page:"
+ "\n1: Check the items available"
+ "\n2: Refill the stock"
+ "\n3: Open the log book"
+ "\n4: Log out as a vendor");
String user = s.nextLine();
switch (user) {
case "1":
hm.display();
VendormainPage();
break;
case "2":
refill();
break;
case "3":
tr.openlog();
VendormainPage();
break;
case "4":
user();
break;
default:
System.out.println("Wrong entry, try again");
VendormainPage();
}
}
public static void refill() throws IOException {
Scanner s = new Scanner(System.in);
int d = 5;
do {
System.out.println("Enter the number of the drink you want to refill");
hm.display();
System.out.println("[9] Back");
String input = s.nextLine();
switch (input) {
case "1":
hm.Stock1("Pikapoo", 1);
break;
case "2":
hm.Stock1("Hell and Sky", 1);
break;
case "3":
hm.Stock1("SkyJuicee", 1);
break;
case "4":
hm.Stock1("Popci", 1);
break;
case "5":
hm.Stock1("MAILO", 1);
break;
case "6":
hm.Stock1("99plus", 1);
break;
case "7":
hm.Stock1("Sepright", 1);
break;
case "8":
hm.Stock1("LeegalCaffeine", 1);
break;
case "9":
d = 6;
VendormainPage();
default:
System.out.println("wrong entry, try again");
refill();
}
} while (d == 5);
}
}