-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMain.java
More file actions
38 lines (30 loc) · 1.18 KB
/
Main.java
File metadata and controls
38 lines (30 loc) · 1.18 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
package org.codedifferently;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scr = new Scanner(System.in);
System.out.println("Enter your name: ");
String name = scr.nextLine();
System.out.println("Enter your budget: ");
double budget = scr.nextDouble();
scr.nextLine(); // consume leftover newline
System.out.println("Enter a coupon code: ");
String couponCode = scr.nextLine();
// Create a Receipt object
Receipt receipt = new Receipt();
receipt.generateItemPrices(); // generates 3 separate items
receipt.calculateSubtotal();
receipt.applyCoupon(couponCode);
receipt.calculateTax();
receipt.calculateFinalTotal();
// Create a Visit object
Visit visit = new Visit(name);
visit.generateReceiptCode();
boolean withinBudget = visit.checkBudget(receipt.finalTotal, budget);
// Print the receipt
System.out.println("\n--- Receipt ---");
visit.printReceiptCode();
receipt.printReceiptDetails();
System.out.println("Within budget: " + withinBudget);
}
}