-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaxTotalCalc.java
45 lines (37 loc) · 1.18 KB
/
TaxTotalCalc.java
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
import java.util.List;
public class TaxTotalCalc {
private Double taxTotal = 0.00;
private Double saleTotal = 0.00;
private Double itemTotal = 0.00;
public TaxTotalCalc(List<Item> items){
for(Item item: items){
this.itemTotal = this.itemTotal + (item.getPrice() * item.getQty());
this.taxTotal = this.taxTotal + computeSalesTax(item);
}
this.saleTotal = this.itemTotal + this.taxTotal;
}
private Double computeSalesTax(Item item){
Double tax = .10;
if (item.isExempt()){
tax = .00;
}
if (item.isImport()){
tax = tax + .05;
}
Double rounded = roundAmount((item.getPrice()*tax) * item.getQty());
item.setAfterTax(rounded + (item.getPrice() * item.getQty()));
return rounded;
}
public Double getTaxTotal() {
return this.taxTotal;
}
public Double getSaleTotal() {
return this.saleTotal;
}
private Double roundAmount(Double amount){
return Math.ceil((amount * 20.0)) / 20.0;
}
private Double computeSaleTotal(){
return this.saleTotal = (this.taxTotal + this.itemTotal);
}
}