-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathReceiptApp.java
More file actions
61 lines (47 loc) · 1.84 KB
/
ReceiptApp.java
File metadata and controls
61 lines (47 loc) · 1.84 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
import java.util.Random;
import java.util.Scanner;
public class ReceiptApp {
public static void run() {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
// User Input
System.out.print("What is your name? ");
String name = scanner.nextLine().trim();
System.out.print("What is your budget? ");
double budget = scanner.nextDouble();
scanner.nextLine();
System.out.print("What is your coupon code: ");
String coupon = scanner.nextLine();
// Random Input
int visitId = PriceGenerator.generateVisitId(random);
double[] items = PriceGenerator.generateItemPrices(random);
double taxRate = PriceGenerator.generateTaxRate(random);
String receiptCode = CodeGenerator.buildReceiptCode(name, visitId);
double subtotal = PriceGenerator.subtotal(items);
double tax = subtotal * taxRate;
double luckyDiscount = PriceGenerator.luckyVisitBonusDiscount(visitId, subtotal);
double mystery = PriceGenerator.mysteryAdjustment(random, subtotal);
double couponDiscount = PriceGenerator.couponDiscount(random, coupon, subtotal);
double total = subtotal + tax + mystery - luckyDiscount - couponDiscount;
total = PriceGenerator.roundMoney(Math.max(0, total));
double remaining = PriceGenerator.roundMoney(budget - total);
ReceiptPrinter.print(
"Ken's Grocery Store",
name,
visitId,
receiptCode,
items,
subtotal,
taxRate,
tax,
mystery,
luckyDiscount,
coupon,
couponDiscount,
total,
budget,
remaining
);
scanner.close();
}
}