-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathReceiptPrinter.java
More file actions
94 lines (59 loc) · 2.55 KB
/
ReceiptPrinter.java
File metadata and controls
94 lines (59 loc) · 2.55 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
public class ReceiptPrinter {
public static void print(
String storeName,
String customerName,
int visitId,
String receiptCode,
double[] items,
double subtotal,
double taxRate,
double tax,
double mysteryAdjustment,
double luckyBonusDiscount,
String coupon,
double couponDiscount,
double total,
double budget,
double remaining
) {
System.out.println();
System.out.println("----- Welcome to " + storeName + " -----");
System.out.println("Customer: " + customerName);
System.out.println("Visit ID: " + visitId);
System.out.println("Receipt Code: " + receiptCode);
System.out.println("----------------------------------------");
for (int i = 0; i < items.length; i++) {
System.out.printf("Item %d: $%.2f%n", (i + 1), items[i]);
}
System.out.println("----------------------------------------");
System.out.printf("Subtotal: $%.2f%n", subtotal);
System.out.printf("Tax (%.1f%%): $%.2f%n", taxRate * 100.0, tax);
if (mysteryAdjustment > 0) {
System.out.printf("Mystery Fee: +$%.2f%n", mysteryAdjustment);
} else if (mysteryAdjustment < 0) {
System.out.printf("Mystery Discount: -$%.2f%n", Math.abs(mysteryAdjustment));
}
if (luckyBonusDiscount > 0) {
System.out.printf("Lucky Visit Bonus: -$%.2f%n", luckyBonusDiscount);
}
if (couponDiscount > 0) {
System.out.printf("Coupon (%s) Applied: -$%.2f%n", coupon.trim().toUpperCase(), couponDiscount);
} else {
System.out.printf("Coupon (%s): Not Applied%n", coupon.trim());
}
System.out.println("----------------------------------------");
System.out.printf("FINAL TOTAL: $%.2f%n", total);
System.out.printf("Budget: $%.2f%n", budget);
if (remaining >= 0) {
System.out.printf("Budget Remaining: $%.2f%n", remaining);
if (remaining < 5) {
System.out.println("WARNING: Tight budget. You're cutting it close.");
}
} else {
System.out.printf("Short By: $%.2f%n", Math.abs(remaining));
System.out.println("WARNING: You do not have enough budget to complete this order.");
}
System.out.println("----------------------------------------");
System.out.println("Thank you. Come again.");
}
}