-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathrecieptcalculator.java
More file actions
75 lines (54 loc) · 1.99 KB
/
recieptcalculator.java
File metadata and controls
75 lines (54 loc) · 1.99 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
package org.codedifferently;
import java.util.Random;
public class recieptcalculator {
private int itemid;
private double itemprice;
private double taxrate;
private double tax;
private double item2price;
private double item3price;
public boolean rewardmember;
public double memberpricing;
public int rewardsmemnum = 00000;
public recieptcalculator() {
Random random = new Random();
itemid = random.nextInt(1000) + 100;
taxrate = random.nextInt((7)) + 3 / 100.0;
itemprice = random.nextInt(400) + 19;
item2price = random.nextInt(30) + 1;
item3price = random.nextInt(60) + 4;
}
public double calculatetax() {
return Round((itemprice + item2price + item3price) * taxrate) / 100;
}
public double calculatetotal() {
return itemprice + item2price + item3price + calculatetax() + tax;
}
public String generatethereceipt() {
String reciept = "";
reciept += "Item ID: " + itemid + "\n";
reciept += "Price: $" + (itemprice) + "\n";
reciept += "Price: $" + (item2price) + "\n";
reciept += "Price: $" + (item3price) + "\n";
reciept += "Tax rate:" + (taxrate) + "\n";
reciept += "Tax:" + calculatetax() + "\n";
recieptcalculator rc = new recieptcalculator();
Main main = new Main();
if (rewardmember == true) {
memberpricing = calculatetotal() / 2;
reciept += "Total: $" + memberpricing + "\n";
} else {
reciept += "Total: $" + calculatetotal() + "\n";
}
if (rewardmember == true) {
memberpricing = calculatetotal() / 2;
reciept += "Total: $" + " " + "(Rounded):" + Round(memberpricing) + "\n";
} else {
reciept += "Total: $(Rounded):" + Round(calculatetotal()) + "\n";
}
return reciept;
}
private double Round(double valuerounded) {
return Math.round(valuerounded * 100) / 100;
}
}