-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlineOrder.java
More file actions
62 lines (58 loc) · 1.71 KB
/
OnlineOrder.java
File metadata and controls
62 lines (58 loc) · 1.71 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
public class OnlineOrder {
private String orderName;
private double totalCost;
private double tax;
private int numTurkey;
private int numItalian;
private int numVeggie;
private int numBLT;
final double TAX_RATE = 0.07;
public OnlineOrder(String name, int turkey, int italian, int veggie, int blt){
orderName = name;
numTurkey = turkey;
numItalian = italian;
numVeggie = veggie;
numBLT = blt;
totalCost = getTotalCost();
tax = getTax();
}
public void changeOrder(int turkey, int italian, int veggie, int blt){
if(turkey > 0){
this.numTurkey = turkey;
} else{
this.numTurkey = 0;
}
if(italian > 0){
this.numItalian = italian;
} else{
this.numItalian = 0;
}
if(veggie > 0){
this.numVeggie = veggie;
} else{
this.numVeggie = 0;
}
if(blt > 0){
this.numBLT = blt;
} else{
this.numBLT = 0;
}
totalCost = (4.99*(turkey+italian+blt)+3.99*veggie);
this.tax = Math.round(100 * totalCost * TAX_RATE)/100.0;
}
public double getTotalCost(){
changeOrder(numTurkey, numItalian, numVeggie, numBLT);
return totalCost;
}
public double getTax(){
changeOrder(numTurkey, numItalian, numVeggie, numBLT);
return tax;
}
public String toString(){
return orderName + ", your order comes to " + (Math.round(100*(getTotalCost() + getTax()))/100.0);
}
public static void main (String[] args){
OnlineOrder order = new OnlineOrder("Sarah",0,0,1,1);
System.out.println(order);
}
}