-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMain.java
More file actions
80 lines (66 loc) · 3.34 KB
/
Main.java
File metadata and controls
80 lines (66 loc) · 3.34 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
package org.codedifferently;
public class Main {
static void main()
{
//Gather all User Info from UserInput class methods
UserInput userInput = new UserInput();
String firstName = userInput.promptUserName(true);
String lastName = userInput.promptUserName(false);
double budget = userInput.promptUserBudget();
String couponCode = userInput.promptCouponCode();
//Print Walmart receipt with dashes for formatting
System.out.println("-----------------------------------------------");
System.out.println("Welcome to Walmart!");
//Calculate visitID
MathCalc mathCalc = new MathCalc();
int visitID = mathCalc.generateRandomNumber(1000,9999);
System.out.println("Visit ID: " + visitID);
//then calculate receiptCode
StringLogic stringLogic = new StringLogic();
String receiptCode = stringLogic.generateReceiptCode(firstName, lastName);
System.out.println("Receipt Code: " + receiptCode);
//generate random item prices
double item1Price = mathCalc.generateRandomNumber(5,75);
double item2Price = mathCalc.generateRandomNumber(10,85);
double item3Price = mathCalc.generateRandomNumber(15, 105);
System.out.println("Item 1: $" + item1Price);
System.out.println("Item 2: $" + item2Price);
System.out.println("Item 3: $" + item3Price);
//generate coupon rate if valid coupon is applied
double couponRate = (stringLogic.checkValidCoupon(couponCode))
? mathCalc.generateCouponDiscount()
: 0;
//calculate total subtotal of all three items
double subTotal = item1Price + item2Price + item3Price;
System.out.println("Subtotal: $" + subTotal);
System.out.println("-----------------------------------------------");
//then calculate a random taxRate
double taxRate = mathCalc.generateTaxRate();
System.out.println("Tax Rate: " + (int)(taxRate * 100) + "%");
//apply coupons ßfor random %ß off as well, if invalid code do not apply discount.
if(couponRate > 0) {
System.out.println("Valid coupon entered!");
System.out.println("Applied " + (couponRate * 100) + "% discount");
}
else {
System.out.println("Invalid coupon code! No discount applied!");
System.out.println("Make sure your coupons start with c-");
}
//calculate final total based on taxes and coupons
double finalTotal = mathCalc.calculateFinalTotal(subTotal, taxRate, couponRate);
System.out.println("Final total: $" + finalTotal);
//get and return budget remaining for user to see. if no budget left, then notify them
double budgetRemaining = mathCalc.calculateRemainingBudget(budget, finalTotal);
if (budgetRemaining < 0)
{
System.out.println("Looks like the items are past your budget! \n" +
"You'll have to pay this amount to continue: \n$" +
mathCalc.calculateAbsoluteValue(budgetRemaining));
}
else {
System.out.println("Budget Remaining: $" + budgetRemaining);
}
System.out.println("Thank you for shopping at Walmart!");
System.out.println("------------------------------------------------");
}
}