willieshi232

Untitled

Mar 28th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. package com.Animu;
  2.  
  3. /**
  4. * Created by WillieShi on 3/16/2016.
  5. */
  6. public class ItemOrder
  7. {
  8. private Item item;
  9. private int quantity;
  10. public ItemOrder(Item item, int quantity)
  11. {
  12. this.item = item;
  13. this.quantity = quantity;
  14. }
  15. public double getPrice()
  16. {
  17. return item.priceFor(quantity);
  18. }
  19. public String getItem()
  20. {
  21. return item.toString();
  22. }
  23. }
  24. package com.Animu;
  25.  
  26. import java.util.*;
  27. public class ShoppingCart
  28. {
  29. private ArrayList<ItemOrder> merch = new ArrayList<ItemOrder>();
  30. private ItemOrder order;
  31. private boolean hasDiscount;
  32. private ItemOrder temp;
  33. public ShoppingCart()
  34. {
  35. merch = new ArrayList<ItemOrder>();
  36. }
  37. public void add(ItemOrder order)
  38. {
  39. this.order = order;
  40. if(merch.contains(order))
  41. {
  42. int x = merch.indexOf(order);
  43. merch.remove(x);
  44. }
  45. merch.add(order);
  46. }
  47. public boolean setDiscount(boolean value)
  48. {
  49. hasDiscount = value;
  50. return hasDiscount;
  51. }
  52. public double getTotal()
  53. {
  54. double price = 0.0;
  55. double tempprice = 0.0;
  56. for(int i = 0; i < merch.size(); i++)
  57. {
  58. temp = merch.get(i);
  59. tempprice = temp.getPrice();
  60. price += tempprice;
  61. }
  62. return price;
  63. }
  64.  
  65.  
  66. }
  67. package com.Animu;
  68.  
  69. import java.util.ArrayList;
  70. public class Catalog
  71. {
  72. private ArrayList<Item> catalog;
  73. private String name;
  74. public Catalog(String name)
  75. {
  76. this.name = name;
  77. }
  78. public void add(Item item)
  79. {
  80. catalog.add(item);
  81. }
  82. public int size()
  83. {
  84. return catalog.size();
  85. }
  86. public Item get(int index)
  87. {
  88. return catalog.get(index);
  89. }
  90. public String getName()
  91. {
  92. return name;
  93. }
  94. }
  95. public class Item
  96. {
  97. private String name;
  98. private double price;
  99. private int bulkquantity;
  100. private double bulkprice;
  101. private int quantity;
  102. public Item(String name, double price)
  103. {
  104. this.name = name;
  105. this.price = price;
  106. if(price < 0)
  107. {
  108. throw new IllegalArgumentException("Error: Price is negative.");
  109.  
  110. }
  111. }
  112. public Item(String name, double price,int bulkquantity, double bulkprice)
  113. {
  114. this.name = name;
  115. this.price = price;
  116. this.bulkquantity = bulkquantity;
  117. this.bulkprice = bulkprice;
  118. if(bulkprice < 0)
  119. {
  120. throw new IllegalArgumentException("Error: bulkprice is negative.");
  121. }
  122. if(price < 0.0)
  123. {
  124. throw new IllegalArgumentException("Error: price is negative");
  125. }
  126. if(bulkquantity < 0.0)
  127. {
  128. throw new IllegalArgumentException("Error: bulkquantity is negative");
  129. }
  130. }
  131. public double priceFor(int quantity)
  132. {
  133. this.quantity = quantity;
  134. if(quantity < 0)
  135. {
  136. throw new IllegalArgumentException("Error: quantity is negative");
  137. }
  138. if(price < 0.0)
  139. {
  140. throw new IllegalArgumentException("Error: price is negative");
  141. }
  142. if(bulkquantity < 0.0)
  143. {
  144. throw new IllegalArgumentException("Error: bulkquantity is negative");
  145. }
  146. if(bulkprice < 0)
  147. {
  148. throw new IllegalArgumentException("Error: bulkprice is negative.");
  149. }
  150. return (price * (quantity % bulkquantity)) + (Math.floor(quantity / bulkquantity) * bulkprice);
  151. }
  152. public String toString()
  153. {
  154. return name + ", "+ price + "in order to buy in bulk you must buy" + bulkquantity + "of the item, at a price of" + bulkprice;
  155.  
  156. }
  157.  
  158. }
  159. package com.Animu;
  160.  
  161. /**
  162. * Created by WillieShi on 3/18/2016.
  163. */
  164. public class ShopMain
  165. {
  166. public static void main(String [] args) {
  167. Item OnePunchManGlove = new Item("One Punch Man Glove", 100.0, 10, 9000.0);
  168. Item NoGameNoLifePoster = new Item("NoGameNoLife Poster", 50.0, 10, 450.0);
  169. Item SaberPoster = new Item("Saber Poster", 25.0, 10, 225.0);
  170. Item KanekiMask = new Item("KanekiMask", 10.0, 10, 95.0);
  171. Item Shigastu = new Item("ShigastuNoKimiNoUso Poster", 24.0, 10, 220.0);
  172. Item Poro = new Item("AssortedMustachedPoro Poster", 32.0, 10, 310.0);
  173. Item Pass = new Item("PshycoPass Denominator", 45.0, 10, 425.0);
  174. Item Erased = new Item("Erased Poster", 31.0, 10, 300.0);
  175. Item TeemoHat = new Item("TeemoHat", 15.0, 10, 135.0);
  176. Item NGNL = new Item("I(>Imanity Shirt", 22.0, 10, 210.0);
  177. Catalog Animu = new Catalog("AnimuShop");
  178. Animu.add(OnePunchManGlove);
  179. Animu.add(NoGameNoLifePoster);
  180. Animu.add(SaberPoster);
  181. Animu.add(KanekiMask);
  182. Animu.add(Shigastu);
  183. Animu.add(Poro);
  184. Animu.add(Pass);
  185. Animu.add(Erased);
  186. Animu.add(TeemoHat);
  187. Animu.add(NGNL);
  188. ShoppingFrame frame = new ShoppingFrame(Animu);
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment