Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.yannickxd2.onlineShop;
- import java.util.ArrayList;
- public class List {
- private ArrayList<PointOfList> list;
- private int numberOfProducts;
- public List() {
- this.list = new ArrayList<PointOfList>();
- this.numberOfProducts = 0;
- }
- /**
- * @return the list
- */
- public ArrayList<PointOfList> getList() {
- return list;
- }
- /**
- * @return the numberOfProducts
- */
- public int getNumberOfProducts() {
- return numberOfProducts;
- }
- public void addProduct(PointOfList p) {
- this.list.add(p);
- this.numberOfProducts++;
- }
- public void removeProduct(int index) {
- this.list.remove(index);
- this.numberOfProducts--;
- }
- public Product findCheapestProduct() {
- Product one = this.list.get(0).getProduct();
- for (int i = 1; i < this.list.size(); i++) {
- if (one.getPrice() < this.list.get(i).getProduct().getPrice()) {
- one = this.list.get(i).getProduct();
- }
- }
- return one;
- }
- public double combinedPrice() {
- double price = 0;
- for (int i = 0; i < this.list.size(); i++) {
- price += this.list.get(i).getProduct().getPrice() * this.list.get(i).getQuantity();
- }
- return price;
- }
- public void print() {
- System.out.println("Your Cart");
- for (int i = 0; i < this.list.size(); i++) {
- System.out.println(" Nr." + (i + 1));
- System.out.println(" " + "Name: " + list.get(i).getProduct().getName());
- System.out.println(" " + "Quantity: " + list.get(i).getQuantity());
- System.out.println(" " + "Price: " + list.get(i).getProduct().getPrice());
- System.out.println(
- " " + "CombinedPrice: " + list.get(i).getProduct().getPrice() * list.get(i).getQuantity());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement