Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package AI164.Tunon;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Cart<T extends Item> {
  6.     private ArrayList<T> cart;
  7.     private double cartAmount;
  8.  
  9.     public void print() {
  10.  
  11.         System.out.println("Cart : \n");
  12.         this.cartAmount = 0;
  13.  
  14.         for (int i = 0; i < this.cart.size(); i++){
  15.  
  16.             System.out.println(this.cart.get(i).getName() + " price :" + this.cart.get(i).getPrice() + " $");
  17.             this.cartAmount += this.cart.get(i).getPrice();
  18.  
  19.         }
  20.  
  21.         System.out.println("\nAmount : " + this.cartAmount + " $");
  22.  
  23.     }
  24.  
  25.  
  26.     public void print(double percent) {
  27.  
  28.         System.out.println("Cart : \n");
  29.         this.cartAmount = 0;
  30.  
  31.         for (int i = 0; i < this.cart.size(); i++){
  32.  
  33.             System.out.println(this.cart.get(i).getName() + " price :" + this.cart.get(i).changePrice(percent) + " $");
  34.             this.cartAmount += this.cart.get(i).changePrice(percent);
  35.  
  36.         }
  37.  
  38.         System.out.println("\nAmount : " + this.cartAmount + " $");
  39.  
  40.     }
  41.  
  42.     public  void add(T item){
  43.         this.cart.add(item);
  44.     }
  45.  
  46.     public Cart(int count) {
  47.         this.cart = new ArrayList<T>(count);
  48.         this.cartAmount = 0;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement