-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathReceiptApp.java
More file actions
70 lines (40 loc) · 1.65 KB
/
ReceiptApp.java
File metadata and controls
70 lines (40 loc) · 1.65 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
package org.codedifferently;
import java.util.Random;
import java.util.Scanner;
public class ReceiptApp {
public static double roundMoney(Double amount){
return Math.round(amount * 100.0) / 100.0;
}
public static void main(String[] args) {
// ==== USER INPUT ====
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your name: ");
String name = scanner.nextLine();
System.out.println("Enter your budget: ");
String budgetText = scanner.nextLine();
double budget = Double.parseDouble(budgetText);
System.out.println("Enter a coupon code: ");
String couponCode = scanner.nextLine();
Random rand = new Random();
int visitId = 1000 + rand.nextInt(9000);
double item1 = 5 + rand.nextDouble() * 35;
double item2 = 10 + rand.nextDouble() * 70;
double item3 = 3 + rand.nextDouble() * 22;
item1 = roundMoney(item1);
item2 = roundMoney(item2);
item3 = roundMoney(item3);
double subTotal = item1 + item2 + item3;
subTotal = roundMoney(subTotal);
System.out.println();
System.out.println("Welcome " + name + "!");
System.out.println("Budget entered: " + budget);
System.out.println("Coupon entered: " + couponCode);
System.out.println("\n--- TEST OUTPUT ---");
System.out.println("Visit ID: " + visitId);
System.out.println("Item 1: " + item1);
System.out.println("Item 2: " + item2);
System.out.println("Item 3: " + item3);
System.out.println("Subtotal: $" + subTotal);
scanner.close();
}
}