-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMain.java
More file actions
80 lines (59 loc) · 3.24 KB
/
Main.java
File metadata and controls
80 lines (59 loc) · 3.24 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.ReceiptApp;
import java.util.Scanner;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//these are the accepted coupon codes
String[] couponCodes = {"25OFF", "50OFF", "75OFF", "100OFF"};
//get username
System.out.println("Please enter your username: ");
Scanner scanner = new Scanner(System.in);
String username = scanner.next();
//get budget
System.out.println("Please enter your budget: ");
double budget = scanner.nextDouble();
//get coupon code
System.out.println("Please enter your coupon code: ");
String couponCode = scanner.next();
//instantiate objects so we can use their methods
RandomGenerations randomItem = new RandomGenerations();
PriceCalculations calculatePrice = new PriceCalculations();
CouponChecker coupon = new CouponChecker();
ConsolePrint output = new ConsolePrint();
//generate random values for discount, fee and rates
boolean isDiscount = randomItem.discount();
double fee = randomItem.fee();
double taxRate = randomItem.tax();
double discountRate = randomItem.tax();
//generate random item IDs
int itemSelectionOne = randomItem.item();
int itemSelectionTwo = randomItem.item();
int itemSelectionThree = randomItem.item();
//generate random items mapped from ID's
StoreItem item1 = new StoreItem(itemSelectionOne, randomItem.prices());
StoreItem item2 = new StoreItem(itemSelectionTwo, randomItem.prices());
StoreItem item3 = new StoreItem(itemSelectionThree, randomItem.prices());
//store item prices in an array to use with subtotal method
double[] itemPrices = {item1.getPrice(), item2.getPrice(), item3.getPrice()};
//calculate sum of item prices
double subTotal = calculatePrice.subtotal(itemPrices);
//calculate price after incorporating fee/lucky discount, tax, etc..
double subFinalTotal = calculatePrice.finalTotal(subTotal, isDiscount, fee, taxRate, discountRate);
//generate random visitID
int visitID = randomItem.visitIDGen();
//generate receiptCode
String fullReceiptCode = randomItem.receiptCode(username, visitID);
//check whether coupon is valid
boolean isValidCoupon = coupon.couponCheck(couponCodes, couponCode);
//if coupon is valid, assigns the discount value
int discountVal = coupon.discountRate(isValidCoupon, couponCodes, couponCode);
//calculate final total after all coupons, taxes, fees, etc. applied
double finalTotal = coupon.applyCoupon(isValidCoupon, subFinalTotal, discountVal);
//moved all print statements and print logic into a class called console print
//method print results takes all of these values we found and prints formatted info to console
output.printResults(visitID, fullReceiptCode, item1, item2,
item3, subTotal, taxRate, isDiscount, discountRate,
fee, isValidCoupon, couponCode, discountVal, finalTotal, budget);
}
}