about summary refs log tree commit diff
path: root/usth/ICT2.2/labwork/3/Java/ShoppingCart.java
blob: f5e23ad6d86de44add8ac3b3c56de8857bff9c61 (plain) (blame)
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
import java.util.ArrayList;
import java.util.List;

public class ShoppingCart
{
  private List<String> cartContents = new ArrayList<String>();

  public boolean addToCart(String content)
  {
    return cartContents.add(content);
  }

  public boolean removeFromCart(String content)
  {
    return cartContents.remove(content);
  }

  public void checkOut()
  {
    cartContents.clear();
  }

  public String toString()
  {
    return "Cart content(s): " + String.join(", ", cartContents);
  }
}