Maya1991

IceCreamProblem

Dec 24th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. ▪️Customer.java
  2.  
  3. public class Customer {
  4. public IceCreamFlavor icecream;
  5. public int price;
  6. private String customerName;
  7. static String hamper;
  8.  
  9. Customer(IceCreamFlavor icecream) {
  10. this.icecream = icecream;
  11. }
  12.  
  13. Customer(IceCreamFlavor icecream, String customerName) {
  14. this.icecream = icecream;
  15. this.customerName = customerName;
  16. }
  17.  
  18. // String getName() {
  19. // return icecream.getName();
  20. // }
  21. //
  22. // int getPrice() {
  23. // return icecream.getPrice();
  24. // }
  25.  
  26. String getCustomerName() {
  27. return this.customerName;
  28. }
  29.  
  30. void setCustomerName(String customerName) {
  31. this.customerName = customerName;
  32.  
  33. }
  34.  
  35. void buy(IceCreamFlavor icecream) {
  36. // not really sure what business do here
  37. // just return the Ice cream.
  38. this.icecream = icecream;
  39.  
  40. }
  41.  
  42. String purchase() {
  43. // not really sure what business do here
  44. // just return the Ice cream.
  45. return icecream.getName();
  46.  
  47. }
  48.  
  49. }
  50.  
  51. ▪️IceCreamShopMain.java
  52. public class IceCreamShopMain {
  53. public static void main(String[] args) {
  54. System.out.println(IceCreamFlavor.HAZELNUT.getName());
  55. System.out.println("The price of ice-cream is " + IceCreamFlavor.HAZELNUT.getPrice() + " dollars.");
  56. Customer c = new Customer(IceCreamFlavor.WHIPPEDCREAM);
  57. c.setCustomerName("Amy");
  58. Customer c2 = new Customer(IceCreamFlavor.ALMOND, "Mawson");
  59. System.out.println(c.getCustomerName() + "`s purchased items are " + c.purchase() + ".");
  60. c.buy(IceCreamFlavor.OREOCOOKIECRUMBLES);
  61. System.out.println(c.purchase());
  62. System.out.println(c.icecream.getName());
  63. System.out.println(c2.getCustomerName() + " bought " + c2.icecream.getName() + "-Ice"
  64. + " which was " + c2.icecream.getPrice() + " dollars.");
  65.  
  66. }
  67. }
  68.  
  69. ▪️IceCreamFlavor.java
  70. enum IceCreamFlavor {
  71.  
  72. HAZELNUT("Hazelnut", 300), WHIPPEDCREAM("WhippedCream", 270), ALMOND("Almond",
  73. 370), OREOCOOKIECRUMBLES("OreoCookieCrumbles", 500), MARSHMALLOWS("Marshmallows", 420);
  74.  
  75. public String name;
  76. public int price;
  77.  
  78. private IceCreamFlavor(String name, int price) {
  79. this.name = name;
  80. this.price = price;
  81. }
  82.  
  83. String getName() {
  84. return name;
  85. }
  86.  
  87. int getPrice() {
  88. return price;
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment