-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCart.java
More file actions
45 lines (41 loc) · 1.14 KB
/
Copy pathCart.java
File metadata and controls
45 lines (41 loc) · 1.14 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
import java.text.DecimalFormat;
import java.util.ArrayList;
/**
* Created by chand on 7/25/2017.
*/
public class Cart {
ArrayList<Items> itemList = new ArrayList<Items>();
DecimalFormat decimalFormat = new DecimalFormat("#.00");
public void addToCart(Items userInput){
itemList.add(userInput);
}
public void displayList() {
for(Items i : itemList){
System.out.println(i);
}
}
public double getSubtotal(){
double subtotal = 0;
for(Items i : itemList){
subtotal = subtotal + i.getSubTotal();
}
return subtotal;
}
public double getSalesTaxes(){
double taxes = 0;
for(Items i : itemList) {
taxes = taxes + i.getTax();
}
return taxes;
}
public double total(){
double total = getSalesTaxes() + getSubtotal();
return total;
}
@Override
public String toString() {
return "Subtotal = " + decimalFormat.format(getSubtotal()) + "\n"
+ "Sales Tax = " + decimalFormat.format(getSalesTaxes()) + "\n"
+ "Total = " + decimalFormat.format(total());
}
}