Advertisement
Alekss33

Untitled

Mar 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package com.telerikacademy.cosmetics.models.cart;
  2.  
  3. import com.telerikacademy.cosmetics.models.contracts.Product;
  4. import com.telerikacademy.cosmetics.models.contracts.ShoppingCart;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. public class ShoppingCartImpl implements ShoppingCart {
  10. private List<Product> productList;
  11.  
  12. public ShoppingCartImpl() {
  13. productList = new ArrayList<>();
  14. }
  15.  
  16. public List<Product> getProductList() {
  17. return new ArrayList<>(productList);
  18. }
  19.  
  20. public void addProduct(Product product) {
  21. if (product == null) {
  22. throw new IllegalArgumentException();
  23. }
  24. productList.add(product);
  25. }
  26.  
  27. public void removeProduct(Product product) {
  28. if (product == null) {
  29. throw new IllegalArgumentException();
  30. }
  31. productList.remove(product);
  32. }
  33.  
  34. public boolean containsProduct(Product product) {
  35. if (product == null) {
  36. throw new IllegalArgumentException();
  37. }
  38. return productList.contains(product);
  39. }
  40.  
  41. public double totalPrice() {
  42. double totalPrice = 0;
  43. for (Product product : productList) {
  44. totalPrice += product.getPrice();
  45. }
  46. return totalPrice;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement