Advertisement
Guest User

List

a guest
Nov 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package com.yannickxd2.onlineShop;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class List {
  6.  
  7. private ArrayList<PointOfList> list;
  8. private int numberOfProducts;
  9.  
  10. public List() {
  11. this.list = new ArrayList<PointOfList>();
  12. this.numberOfProducts = 0;
  13. }
  14.  
  15. /**
  16. * @return the list
  17. */
  18. public ArrayList<PointOfList> getList() {
  19. return list;
  20. }
  21.  
  22. /**
  23. * @return the numberOfProducts
  24. */
  25. public int getNumberOfProducts() {
  26. return numberOfProducts;
  27. }
  28.  
  29. public void addProduct(PointOfList p) {
  30. this.list.add(p);
  31. this.numberOfProducts++;
  32. }
  33.  
  34. public void removeProduct(int index) {
  35. this.list.remove(index);
  36. this.numberOfProducts--;
  37. }
  38.  
  39. public Product findCheapestProduct() {
  40. Product one = this.list.get(0).getProduct();
  41. for (int i = 1; i < this.list.size(); i++) {
  42. if (one.getPrice() < this.list.get(i).getProduct().getPrice()) {
  43. one = this.list.get(i).getProduct();
  44. }
  45. }
  46. return one;
  47. }
  48.  
  49. public double combinedPrice() {
  50. double price = 0;
  51. for (int i = 0; i < this.list.size(); i++) {
  52. price += this.list.get(i).getProduct().getPrice() * this.list.get(i).getQuantity();
  53. }
  54. return price;
  55. }
  56.  
  57. public void print() {
  58. System.out.println("Your Cart");
  59. for (int i = 0; i < this.list.size(); i++) {
  60. System.out.println(" Nr." + (i + 1));
  61. System.out.println(" " + "Name: " + list.get(i).getProduct().getName());
  62. System.out.println(" " + "Quantity: " + list.get(i).getQuantity());
  63. System.out.println(" " + "Price: " + list.get(i).getProduct().getPrice());
  64. System.out.println(
  65. " " + "CombinedPrice: " + list.get(i).getProduct().getPrice() * list.get(i).getQuantity());
  66. }
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement