Maya1991

IceCreamProject(Before Fix)

Dec 24th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. ▪️IceCreamShopMain.java
  2. public class IceCreamShopMain {
  3. public static void main(String[] args) {
  4. System.out.println(IceCreamFlavor.HAZELNUT.getName());
  5. System.out.println("The price of ice-cream is " + IceCreamFlavor.HAZELNUT.getPrice() + " dollars.");
  6. Customer c = new Customer(IceCreamFlavor.WHIPPEDCREAM);
  7. c.setCustomerName("Amy");
  8. Customer c2 = new Customer(IceCreamFlavor.ALMOND, "Mawson");
  9. System.out.println(c.getCustomerName() + "`s purchased items are " + c.printPurchasedIceCreams() + ".");
  10. c.buy(IceCreamFlavor.OREOCOOKIECRUMBLES);
  11. System.out.println(c.printPurchasedIceCreams());
  12. System.out.println(c.icecream.getName());
  13. System.out.println(c2.getCustomerName() + " bought " + c2.icecream.getName() + "-Ice"
  14. + " which was " + c2.icecream.getPrice() + " dollars.");
  15. Customer c3 = new Customer(IceCreamFlavor.OREOCOOKIECRUMBLES, "Mickey");
  16. c3.buy(IceCreamFlavor.ALMOND);
  17. c3.buy(IceCreamFlavor.WHIPPEDCREAM);
  18. System.out.println(c3.printPurchasedIceCreams());
  19.  
  20. }
  21. }
  22.  
  23. ▪️Customer.java
  24. import java.util.*;
  25. public class Customer {
  26. public IceCreamFlavor icecream;
  27. public int price;
  28. private String customerName;
  29. static String hamper;
  30.  
  31. List<IceCreamFlavor> purchasedIceCreams = new ArrayList<IceCreamFlavor>();
  32.  
  33.  
  34. Customer(IceCreamFlavor icecream) {
  35. this.icecream = icecream;
  36. }
  37.  
  38. Customer(IceCreamFlavor icecream, String customerName) {
  39. this.icecream = icecream;
  40. this.customerName = customerName;
  41. }
  42.  
  43. // String getName() {
  44. // return icecream.getName();
  45. // }
  46. //
  47. // int getPrice() {
  48. // return icecream.getPrice();
  49. // }
  50.  
  51. String getCustomerName() {
  52. return this.customerName;
  53. }
  54.  
  55. void setCustomerName(String customerName) {
  56. this.customerName = customerName;
  57.  
  58. }
  59.  
  60. void buy(IceCreamFlavor icecream) {
  61. // not really sure what business do here
  62. // just return the Ice cream.
  63. // this.icecream = icecream;
  64. purchasedIceCreams.add(icecream);
  65.  
  66. }
  67.  
  68. IceCreamFlavor printPurchasedIceCreams() {
  69. // not really sure what business do here
  70. // just return the Ice cream.
  71. for(int i = 0; i < purchasedIceCreams.size(); i++) {
  72. purchasedIceCreams.get(i);
  73.  
  74.  
  75.  
  76. return purchasedIceCreams.get(i);
  77.  
  78.  
  79. }
  80. }
  81. }
  82.  
  83. ▪️IceCreamFlavor.java
  84. enum IceCreamFlavor {
  85.  
  86. HAZELNUT("Hazelnut", 300), WHIPPEDCREAM("WhippedCream", 270), ALMOND("Almond",
  87. 370), OREOCOOKIECRUMBLES("OreoCookieCrumbles", 500), MARSHMALLOWS("Marshmallows", 420);
  88.  
  89. public String name;
  90. public int price;
  91.  
  92. private IceCreamFlavor(String name, int price) {
  93. this.name = name;
  94. this.price = price;
  95. }
  96.  
  97. String getName() {
  98. return name;
  99. }
  100.  
  101. int getPrice() {
  102. return price;
  103. }
  104.  
  105. }
  106.  
  107. ▪️Error Log
  108. Exception in thread "main" java.lang.Error: Unresolved compilation problem:
  109. This method must return a result of type IceCreamFlavor
  110.  
  111. at Customer.printPurchasedIceCreams(Customer.java:45)
  112. at IceCreamShopMain.main(IceCreamShopMain.java:8)
  113. This method must return a result of type
  114. IceCreamFlavor
Advertisement
Add Comment
Please, Sign In to add comment