-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cart.java
41 lines (39 loc) · 905 Bytes
/
Cart.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
import java.util.ArrayList;
/*
* Class Cart defines the cart for each customer
* Contains an ArrayList of CartItems and different
* Methods to interact with the List
*/
public class Cart {
// Variables
private ArrayList<CartItem> cartItems;
// Main Cart Constructor
public Cart()
{
cartItems = new ArrayList<CartItem>();
}
// Print the contents of the cart
public void print()
{
// Loop through each item
for (CartItem item : cartItems)
{
item.print();
}
}
// Add the item to the cart
public void addToCart(CartItem item)
{
cartItems.add(item);
}
// Remove the item from the cart
public void removeFromCart(CartItem item)
{
cartItems.remove(item);
}
// Get the Array List
public ArrayList<CartItem> getList()
{
return cartItems;
}
}