Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Animu;
- /**
- * Created by WillieShi on 3/16/2016.
- */
- public class ItemOrder
- {
- private Item item;
- private int quantity;
- public ItemOrder(Item item, int quantity)
- {
- this.item = item;
- this.quantity = quantity;
- }
- public double getPrice()
- {
- return item.priceFor(quantity);
- }
- public String getItem()
- {
- return item.toString();
- }
- }
- package com.Animu;
- import java.util.*;
- public class ShoppingCart
- {
- private ArrayList<ItemOrder> merch = new ArrayList<ItemOrder>();
- private ItemOrder order;
- private boolean hasDiscount;
- private ItemOrder temp;
- public ShoppingCart()
- {
- merch = new ArrayList<ItemOrder>();
- }
- public void add(ItemOrder order)
- {
- this.order = order;
- if(merch.contains(order))
- {
- int x = merch.indexOf(order);
- merch.remove(x);
- }
- merch.add(order);
- }
- public boolean setDiscount(boolean value)
- {
- hasDiscount = value;
- return hasDiscount;
- }
- public double getTotal()
- {
- double price = 0.0;
- double tempprice = 0.0;
- for(int i = 0; i < merch.size(); i++)
- {
- temp = merch.get(i);
- tempprice = temp.getPrice();
- price += tempprice;
- }
- return price;
- }
- }
- package com.Animu;
- import java.util.ArrayList;
- public class Catalog
- {
- private ArrayList<Item> catalog;
- private String name;
- public Catalog(String name)
- {
- this.name = name;
- }
- public void add(Item item)
- {
- catalog.add(item);
- }
- public int size()
- {
- return catalog.size();
- }
- public Item get(int index)
- {
- return catalog.get(index);
- }
- public String getName()
- {
- return name;
- }
- }
- public class Item
- {
- private String name;
- private double price;
- private int bulkquantity;
- private double bulkprice;
- private int quantity;
- public Item(String name, double price)
- {
- this.name = name;
- this.price = price;
- if(price < 0)
- {
- throw new IllegalArgumentException("Error: Price is negative.");
- }
- }
- public Item(String name, double price,int bulkquantity, double bulkprice)
- {
- this.name = name;
- this.price = price;
- this.bulkquantity = bulkquantity;
- this.bulkprice = bulkprice;
- if(bulkprice < 0)
- {
- throw new IllegalArgumentException("Error: bulkprice is negative.");
- }
- if(price < 0.0)
- {
- throw new IllegalArgumentException("Error: price is negative");
- }
- if(bulkquantity < 0.0)
- {
- throw new IllegalArgumentException("Error: bulkquantity is negative");
- }
- }
- public double priceFor(int quantity)
- {
- this.quantity = quantity;
- if(quantity < 0)
- {
- throw new IllegalArgumentException("Error: quantity is negative");
- }
- if(price < 0.0)
- {
- throw new IllegalArgumentException("Error: price is negative");
- }
- if(bulkquantity < 0.0)
- {
- throw new IllegalArgumentException("Error: bulkquantity is negative");
- }
- if(bulkprice < 0)
- {
- throw new IllegalArgumentException("Error: bulkprice is negative.");
- }
- return (price * (quantity % bulkquantity)) + (Math.floor(quantity / bulkquantity) * bulkprice);
- }
- public String toString()
- {
- return name + ", "+ price + "in order to buy in bulk you must buy" + bulkquantity + "of the item, at a price of" + bulkprice;
- }
- }
- package com.Animu;
- /**
- * Created by WillieShi on 3/18/2016.
- */
- public class ShopMain
- {
- public static void main(String [] args) {
- Item OnePunchManGlove = new Item("One Punch Man Glove", 100.0, 10, 9000.0);
- Item NoGameNoLifePoster = new Item("NoGameNoLife Poster", 50.0, 10, 450.0);
- Item SaberPoster = new Item("Saber Poster", 25.0, 10, 225.0);
- Item KanekiMask = new Item("KanekiMask", 10.0, 10, 95.0);
- Item Shigastu = new Item("ShigastuNoKimiNoUso Poster", 24.0, 10, 220.0);
- Item Poro = new Item("AssortedMustachedPoro Poster", 32.0, 10, 310.0);
- Item Pass = new Item("PshycoPass Denominator", 45.0, 10, 425.0);
- Item Erased = new Item("Erased Poster", 31.0, 10, 300.0);
- Item TeemoHat = new Item("TeemoHat", 15.0, 10, 135.0);
- Item NGNL = new Item("I(>Imanity Shirt", 22.0, 10, 210.0);
- Catalog Animu = new Catalog("AnimuShop");
- Animu.add(OnePunchManGlove);
- Animu.add(NoGameNoLifePoster);
- Animu.add(SaberPoster);
- Animu.add(KanekiMask);
- Animu.add(Shigastu);
- Animu.add(Poro);
- Animu.add(Pass);
- Animu.add(Erased);
- Animu.add(TeemoHat);
- Animu.add(NGNL);
- ShoppingFrame frame = new ShoppingFrame(Animu);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment