-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathRecieptGenerator.java
More file actions
92 lines (43 loc) · 1.82 KB
/
RecieptGenerator.java
File metadata and controls
92 lines (43 loc) · 1.82 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
package org.codedifferently;
import java.util.Random;
/// jj
public class RecieptGenerator {
public int randomIdCode(){
Random random = new Random();
return random.nextInt(100, 999);
}
public void receiptCode(String name, int iD){
String iDName = name.substring(0, 2);
System.out.println("ID: " + iD);
System.out.println("Your Receipt: " + iDName.toUpperCase() + "-" + iD);
}
public double itemPrices (){
Random random = new Random();
double item1 = random.nextDouble(10.00, 50.00);
double item2 = random.nextDouble(10.00, 50.00);
double item3 = random.nextDouble(10.00, 50.00);
System.out.println("Item 1: " + Math.round(item1*100.0)/100.0);
System.out.println("Item 2: " + Math.round(item2*100.0)/100.0);
System.out.println("Item 3: " + Math.round(item3*100.0)/100.0);
double subTotal = item1 + item2 + item3;
System.out.println("Subtotal: " + Math.round(subTotal*100.0)/100.0);
return subTotal;
}
public double itemTax (double subTotal){
Random random = new Random();
int tax = random.nextInt(10);
System.out.println("Item Tax: " + tax + "%");
double taxAmount = subTotal * tax / 100;
System.out.printf("Final Total: %.2f%n", (subTotal + taxAmount));
return subTotal + taxAmount;
}
public void canYouAffordIt(double total, double budget){
double finalTotal = total - budget;
if(budget < total){
System.out.println("You don't have enough. You need " + Math.round(finalTotal*100.0)/100.0 + " to complete order");
}
else{
System.out.println("You have enough! your change is " + Math.abs(Math.round(finalTotal*100.0)/100.0 ) + ".");
}
}
}