-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomework1.java
More file actions
437 lines (389 loc) · 13.4 KB
/
homework1.java
File metadata and controls
437 lines (389 loc) · 13.4 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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
import java.util.*;
//Java CS 401
//Professor Sosnowski's Class
// Galen Switzer
// Assignment 1 2-23-23
public class RealHomework1 {
// check to see if greeted, and based on that, display member greeting, and then determine which price list is displayed based on member flag.
public static void showPriceList (boolean member,int [] memberPrices, int []regularPrices, String [] itemsForsale,boolean greeted) {
if (!greeted && member == true) {
System.out.println("Welcome Member!!! \nEnjoy our items at a discounted price!\nAn additional 10% discount is applied to orders of 10 Sickles or more.");
}
// member prices.
if (member) {
System.out.println("Here is the price list for members.");
// iterate thru array of member price + items
for (int i = 0 ; i < 5 ; i++)
{
System.out.println(itemsForsale [i] + " " + memberPrices[i] + " knuts.");
}
}
// loop for non member non discounted.
else{
System.out.println("Here is our regular price list:");
for (int i = 0; i < 5; i++)
{
System.out.println(itemsForsale[i] + " " + regularPrices[i] + " knuts.");
}
}
}
public static void showOptions () {
String [] Options = {"1)Update Acid Pops Order", "2)Update Pumpkin Pasties Order","3)Update Every Flavour Beans Order","4)Show Price List","5)Show Current Subtotal", "6)Check Out"};
System.out.println("Please choose an option:");
for (int i = 0; i < 6; i++) {
System.out.println(Options[i]);
}
}
public static void main(String[] args){
boolean main = true;
while (main){
// creates scanner object to take in input stream.
Scanner inputStream = new Scanner(System.in);
//allocating memory to an array
//int memberPrices [] = new int [3];
String Password = "test";
// items are ordered -- loook at the string array to figure it out each item index / price
int [] selectedItem = {0,0,0,0,0};
int [] memberPrices = {11,50,100,50,58};
int [] regularPrices = {12,58,116,50,70};
String [] itemsForsale = {"Acid Pop",
"Acid Pops (bag of 5)",
"Pumpkin Pasties",
"Every Flavour Beans (Small Bag)",
"Every Flavour beans (Large Bag)"};
int triesleft = 2;
int change = 0;
int kChange = 0;
int sChange = 0;
int gChange = 0;
boolean browsing = false;
boolean customer = false;
boolean member = false;
boolean greeted =false;
boolean checkOut = false;
int totalPops = 0;
int remainder = 0;
int subTotal = 0;
int knuts = 1;
int sickle = 29;
int galleon = 493 ;
int memberSubTotal = 0;
System.out.println("Welcome to the HoneyPot!");
System.out.println("[Official Licensed HoneyDukes Franchise]");
// loop that handles customer.
// check to see if customer, and if yes, then continue, otherwise exit.
while (!customer)
{
System.out.println("Is there a customer waiting? \nEnter yes or no");
String userInput = inputStream.nextLine().toLowerCase();
if (userInput.equals("no")|| userInput.equals("n")){
inputStream.close();
System.exit(1);
}
else if (userInput.equals("yes")|| userInput.equals("y")){
customer = true;
}
}
// loop checks for password, 2 tries.
while (triesleft > 0){
System.out.println("What is the password?");
String userInput = inputStream.nextLine().toLowerCase();
if (userInput.equals("")){
System.out.println("Silly! You need to actually tell me a password!");
}
if(userInput.equals(Password)){
member = true;
break;
}
else if (!userInput.equals(Password) && !userInput.equals(""))
{
triesleft --;
System.out.println("Sorry, that's not right. Tries left:" + triesleft);
if (triesleft == 0){
System.out.println("You're out of tries! Better luck next time.");
}
}
}
browsing = true;
showPriceList(member, memberPrices, regularPrices, itemsForsale,greeted);
greeted = true;
int itemsToBuy = 0;
while (browsing)
{
showOptions();
int userSelectOption = inputStream.nextInt();
switch(userSelectOption)
{
case 1:
totalPops = selectedItem[0] + selectedItem[1]*5;
// handle prompt based on if user has any acid pops already selected to purchase.
if (selectedItem[0] >= 1 || selectedItem[1] >= 1) {
System.out.println("Here is your current order:");
System.out.println("Acid Pops Selected (single):"+ selectedItem[0] + "\nAcid Pops (bag of 5):" + selectedItem[1]);
System.out.println("How many would you like to add or remove? Enter in singular amounts of Acid Pops.");
}
else {
System.out.println("How many would you like? Enter in singular amounts of Acid Pops.");
}
int userInput = inputStream.nextInt();
if (userInput > 0){
totalPops = totalPops + userInput ;
}
else
{
totalPops = totalPops + userInput;
}
// handles the conversion of bags to single.
if (totalPops >= 5){
selectedItem[0] = totalPops % 5;
selectedItem[1] = totalPops / 5 ;
}
else {
selectedItem[1] = 0;
selectedItem[0] = totalPops;
}
// prevents negative amounts if user goes crazy.
if (selectedItem[0] < 0){
selectedItem[0] = 0;
}
if (selectedItem[1] < 0){
selectedItem[1] = 0;
}
break;
case 2:
if(selectedItem[2] >=1) {
System.out.println("How many would you like to add or remove?");
System.out.println("Here is your current order:");
System.out.println("Pumpkin Pasties:"+ selectedItem[2]);
}
else
{
System.out.println("How many would you like?");
}
userInput = inputStream.nextInt();
selectedItem[2] = userInput + selectedItem[2];
if (selectedItem[2] < 0) {
selectedItem[2] = 0;
}
break;
case 3:
if (selectedItem[3] >=1 || selectedItem [4] >=1){
System.out.println("Here is your current order:");
System.out.println("Every Flavour Beans Small Bag:" + selectedItem[3] + "\nEvery Flavour Beans Large Bag:" + selectedItem[4]);
System.out.println ("How many small bags do you want to add or remove to your order?");
userInput = inputStream.nextInt();
selectedItem[3] = userInput + selectedItem[3];
System.out.println("How many large bags do you want to add or remove to your order?");
userInput = inputStream.nextInt();
selectedItem[4] = userInput + selectedItem[4];
}
else
{
System.out.println("How many small bags do you want?");
userInput = inputStream.nextInt();
selectedItem[3] = userInput + selectedItem[3];
System.out.println("How many large bags do you want?");
userInput = inputStream.nextInt();
selectedItem[4] = userInput + selectedItem[4];
}
if (selectedItem[3] < 0 ){
selectedItem[3] = 0;
}
if (selectedItem[4] < 0) {
selectedItem[4] = 0;
}
break;
case 4:
showPriceList(member, memberPrices, regularPrices, itemsForsale,greeted);
break;
case 5:// subtotal section I calculate all of the items that are stored in the arrays. If you are a member,
// then you get whatever is in your inventory displayed back in stdout.
subTotal = 0;
itemsToBuy = 0;
itemsToBuy = selectedItem [0] + selectedItem[1] + selectedItem[2] + selectedItem[3] + selectedItem[4];
if (member && itemsToBuy >=1)
{
System.out.println("Here is your subtotal:");
for (int i = 0 ; i < 5 ; i++)
{
if (selectedItem[i] == 0){
continue;
}
System.out.println(selectedItem[i] + " " + itemsForsale[i] + " " + memberPrices[i]+ " each unit");
}
}
else if(!member && itemsToBuy >=1) {
System.out.println("Here is your subtotal:");
for (int i = 0; i < 5 ; i++)
{
if (selectedItem[i] == 0)
{
continue;
}
System.out.println(selectedItem[i] + " " + itemsForsale[i] + " " + regularPrices[i]+ " each unit");
}
}
else {
System.out.println("No items selected to purchase. Cannot display subtotal at this time.");
break;
}
if (member) {
for (int i = 0; i < 5 ; i++ ) {
subTotal = selectedItem[i] * memberPrices[i] + subTotal;
}
}
else {
for (int i = 0; i < 5 ; i++ ) {
subTotal = selectedItem[i] * regularPrices[i] + subTotal;
}
}
System.out.println("--------------------------------------------------");
System.out.println(subTotal + " knuts");
//apply 10% disc
if (member && subTotal >= 290){
double discount = 0;
discount = subTotal *.10;
System.out.println("--------------------------------------------------");
System.out.println(subTotal - discount + " knuts" + " after the 10% discount applied!");
}
break;
case 69:
System.out.println("Real mature...");
break;
case 420:
System.out.println("420 Blaze it!!");
break;
default:
System.out.println("Thats not an available option.");
break;
case 6:
subTotal = 0;
itemsToBuy = 0;
itemsToBuy = selectedItem [0] + selectedItem[1] + selectedItem[2] + selectedItem[3] + selectedItem[4];
if (member && itemsToBuy >=1)
{
System.out.println("Here is your subtotal:");
System.out.println("-----------------------------");
for (int i = 0 ; i < 5 ; i++)
{
if (selectedItem[i] == 0){
continue;
}
System.out.println(selectedItem[i] + " " + itemsForsale[i] + " " + memberPrices[i]+ " each unit");
}
}
else if(!member && itemsToBuy >=1) {
System.out.println("Here is your subtotal:");
System.out.println("-----------------------------");
for (int i = 0; i < 5 ; i++)
{
if (selectedItem[i] == 0)
{
continue;
}
System.out.println(selectedItem[i] + " " + itemsForsale[i] + " " + regularPrices[i]+ " each unit");
}
}
else {
System.out.println("No items selected to purchase. Cannot checkout at this time.");
System.out.println("Goodbye.");
System.exit(1);
break;
}
if (member) {
for (int i = 0; i < 5 ; i++ ) {
subTotal = selectedItem[i] * memberPrices[i] + subTotal;
}
}
else {
for (int i = 0; i < 5 ; i++ ) {
subTotal = selectedItem[i] * regularPrices[i] + subTotal;
}
}
System.out.println("--------------------------------------------------");
System.out.println(subTotal + " knuts, is your grand total.");
//apply 10% disc
if (member && subTotal >= 290){
int discount = 0;
discount = subTotal / 10;
memberSubTotal = subTotal - discount;
System.out.println("--------------------------------------------------");
System.out.println(memberSubTotal + " knuts" + " total, after the 10% discount applied!");
}
browsing = false;
}
}
// checkout loop
System.out.println("Note 1: We prefer exact change, but will make change if necessary!");
System.out.println("Note 2: No more than 50 galleons are kept in the cart (funds are transported to Gringotts on a daily basis)");
System.out.println("Note 3: Recall our currency options:");
System.out.println("1 Sickle = 29 Knuts, 17 Sickles = 1 Galleon = 493 Knuts");
System.out.println("Please enter a payment amount in the following format:");
System.out.println("<amount><space><currency>");
System.out.println("Where <amount> = an integer");
System.out.println("Where <space> = a blank space");
System.out.println("Where <currency> = {Knuts, Sickles, Galleons}");
System.out.println("You may enter as many times as you like. Each entry will be added to your total until sufficient funds have been obtained");
checkOut = true;
if (member) {
subTotal = memberSubTotal;
}
while (checkOut){
// take in input for payment & currency
int payment = inputStream.nextInt();
String currencyType = inputStream.nextLine().strip().toLowerCase();
// prevent negative payments.
if (payment <= 0) {
payment = 0;
System.out.println("Please enter a valid payment");
continue;
}
// handles currency type value conversion to KNUTS.
if (currencyType.equals("galleon") || currencyType.equals("galleons")){
payment = payment * 493;
}
else if (currencyType.equals("sickle") || currencyType.equals("sickles"))
{
payment = payment * 29;
}
// displays user payment and subtotal.
System.out.println("Your Payment is: " + payment + " Knuts in value");
System.out.println("Subtotal: " + subTotal + " knuts");
subTotal = subTotal - payment;
change = subTotal * -1;
if (subTotal > 0){
System.out.println("Remaining Payment: " + subTotal + " knuts");
}
// if payment 1 - 2
if (change > 0 && change <29) {
System.out.println("Here is your change " + change + " knuts");
}
if (change > 29 && change < 493) {
sChange = change / 29;
kChange = change % 29;
System.out.println("Here is your change:" + "" + sChange + " sickles " + kChange + " knuts");
}
if (change >=493) {
gChange = change / 493;
remainder = change % 493;
if ( remainder < 29){
kChange = remainder;
}
else if (remainder > 29 && remainder < 493) {
sChange = remainder / 29;
if (sChange >= 17) {
sChange = 0;
}
kChange = remainder % 29;
}
System.out.println("Here is your change: " +"Galleons: " + gChange +" Sickles: " + sChange + " knuts: " + kChange);
}
// break back to main loop
if(subTotal <= 0 ){
System.out.println("Thanks for visiting!! Come again soon!");
break;
}
}
}
}
}