Maya1991

IceCreamCrepeProject

Dec 25th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.65 KB | None | 0 0
  1. ▪️IceCreamShopMain.java
  2. import static java.lang.System.*;
  3.  
  4. public class IceCreamShopMain {
  5.     public static void main(String[] args) {
  6.         System.out.println(IceCreamFlavor.HAZELNUT.getName());
  7.         System.out.println("The price of ice-cream is " + IceCreamFlavor.HAZELNUT.getPrice() + " dollars.");
  8.         Customer c = new Customer(IceCreamFlavor.WHIPPEDCREAM);
  9.         c.setCustomerName("Amy");
  10.         Customer c2 = new Customer(IceCreamFlavor.ALMOND, "Mawson");
  11.         System.out.println(c.getCustomerName() + "`s purchased items are " + c.printPurchasedIceCreams() + ".");
  12.         c.buy(IceCreamFlavor.OREOCOOKIECRUMBLES);
  13.         System.out.println(c.getCustomerName() + " bought " + c.printPurchasedIceCreams());
  14.         out.println("ITS TEST");
  15.         System.out.println(c.icecream);
  16.         System.out.println(c2.getCustomerName() + " bought " + c2.icecream.getName() + "-Ice" + " which was "
  17.                 + c2.icecream.getPrice() + " dollars.");
  18.         Customer c3 = new Customer(IceCreamFlavor.OREOCOOKIECRUMBLES, "Mickey");
  19.         c3.buy(IceCreamFlavor.ALMOND);
  20.         c3.buy(IceCreamFlavor.WHIPPEDCREAM);
  21.         System.out.println(c3.printPurchasedIceCreams());
  22.         Customer c4 = new Customer(IceCreamFlavor.HAZELNUT, "Miley");
  23.         c4.buy(IceCreamFlavor.MARSHMALLOWS);
  24.         out.println("What " + c4.getCustomerName() + " has got? " + c4.printPurchasedIceCreams());
  25.  
  26.         Customer c5 = new Customer(CrepeFlavor.MIEL, "Luise");
  27.         System.out.println(c5.getCustomerName() + " went to FrenchCrepeShop.");
  28.         out.println(c5.getCustomerName() + " bought " + c5.crepe.getName() + " which was " + c5.crepe.getPrice()
  29.                 + " dollars.");
  30.         out.println(c5.crepe.getName());
  31.         out.println("c5's name is " + c5.getCustomerName());
  32.  
  33.         // [story]Customer Sizler went to the crepe shop.
  34.         Customer c6 = new Customer("Sizler");
  35.         c6.buy(CrepeFlavor.GRANDMARNIERSUCRE);
  36.         c6.buy(CrepeFlavor.NOIXDECOCO);
  37.         c6.printPurchasedCrepes();
  38.         // [story]Customer Sizler went to the ice-cream shop.
  39.         System.out.println(c6.getCustomerName());
  40.  
  41.         Customer c7 = new Customer(IceCreamFlavor.HAZELNUT);
  42.         c7.buy(IceCreamFlavor.ALMOND);
  43.         c7.printPurchasedIceCreams();
  44.         out.println(c7.getFirstPurchasedIceCreams());
  45.  
  46.     }
  47.  
  48. }
  49.  
  50.     }
  51.  
  52. }
  53.  
  54. ▪️Customer.java
  55. import java.util.*;
  56.  
  57. public class Customer {
  58.     public IceCreamFlavor icecream;
  59.     // It is strange for object-oriented that in this Customerfield,
  60.     // declaring a variable "price"
  61.     // Why Customer has already have ice-cream price
  62.     // information?It is strange for object-oriented
  63.     // public int price;
  64.  
  65.     private String customerName;
  66.     public CrepeFlavor crepe;
  67.  
  68.     List<IceCreamFlavor> purchasedIceCreams = new ArrayList<IceCreamFlavor>();
  69.     List<CrepeFlavor> purchasedCrepes = new ArrayList<CrepeFlavor>();
  70.     List<IceCreamFlavor> purchasedIceCreams2 = new ArrayList<IceCreamFlavor>();
  71.  
  72.     Customer(IceCreamFlavor icecream) {
  73.         this.icecream = icecream;
  74.         purchasedIceCreams.add(icecream);
  75.     }
  76.  
  77.     Customer(IceCreamFlavor icecream, String customerName) {
  78.         this.icecream = icecream;
  79.         purchasedIceCreams.add(icecream);
  80.         this.customerName = customerName;
  81.     }
  82.  
  83.     Customer(CrepeFlavor crepe) {
  84.         purchasedCrepes.add(crepe);
  85.     }
  86.  
  87.     Customer(CrepeFlavor crepe, String customerName) {
  88.         this.crepe = crepe;
  89.         purchasedCrepes.add(crepe);
  90.         this.customerName = customerName;
  91.     }
  92.  
  93.     Customer(String customerName) {
  94.         this.customerName = customerName;
  95.     }
  96.  
  97.     String getCustomerName() {
  98.         return this.customerName;
  99.     }
  100.  
  101.     void setCustomerName(String customerName) {
  102.         this.customerName = customerName;
  103.  
  104.     }
  105.  
  106.     void buy(IceCreamFlavor icecream) {
  107.         // not really sure what business do here
  108.         // just return the Ice cream.
  109.         // this.icecream = icecream;
  110.         purchasedIceCreams.add(icecream);
  111.     }
  112.  
  113.     void buy(CrepeFlavor crepe) {
  114.         purchasedCrepes.add(crepe);
  115.     }
  116.  
  117.     // this method must be changed its name getPurchasedIceCreams()
  118.     List<IceCreamFlavor> printPurchasedIceCreams() {
  119.         for (int i = 0; i < purchasedIceCreams.size(); i++) {
  120.             System.out.print(purchasedIceCreams.get(i));
  121.             System.out.print(" ");
  122.  
  123.         }
  124.  
  125.         return purchasedIceCreams;
  126.     }
  127.  
  128.      void printPurchasedIceCreams3() {
  129.      for (int i = 0; i < purchasedIceCreaams.size(); i++) {
  130.      System.out.print(purchasedIceCreams.get(i));
  131.      }
  132.      }
  133.  
  134.     IceCreamFlavor getFirstPurchasedIceCreams() {
  135.         // this method which returns the first ice cream
  136.         return purchasedIceCreams.get(0);
  137.     }
  138.  
  139.     void printPurchasedCrepes() {
  140.         for (CrepeFlavor crepe : purchasedCrepes) {
  141.             System.out.print(crepe + " ");
  142.         }
  143.         System.out.println("");
  144.     }
  145.  
  146.     // List<IceCreamFlavor> printPurchasedIceCreams2() {
  147.     // for(int i = 0; i < purchasedIceCreams2.size(); i++) {
  148.     // purchasedIceCreams.get(i);
  149.     // }
  150.     // return null;
  151.     // }
  152. }
  153.  
  154.  
  155. ▪️IceCreamFlavor.java
  156. import java.util.*;
  157.  
  158. enum IceCreamFlavor {
  159.  
  160.     HAZELNUT("Hazelnut", 300), WHIPPEDCREAM("WhippedCream", 270), ALMOND("Almond",
  161.             370), OREOCOOKIECRUMBLES("OreoCookieCrumbles", 500), MARSHMALLOWS("Marshmallows", 420);
  162.  
  163.     public String name;
  164.     public int price;
  165.     List<String> iceCreamNames = new ArrayList<String>();
  166.  
  167.     private IceCreamFlavor(String name, int price) {
  168.         this.name = name;
  169.         iceCreamNames.add(name);
  170.         this.price = price;
  171.     }
  172.  
  173.     String getName() {
  174.         return name;
  175.     }
  176.     // List<String> printIceCreamName() {
  177.     //
  178.     // return iceCreamNames.get(i);
  179.     //
  180.     // }
  181.     //
  182.  
  183.     int getPrice() {
  184.         return price;
  185.     }
  186.  
  187. }
  188.  
  189. ▪️CrepeFlavor.java
  190. import java.util.*;
  191.  
  192. enum CrepeFlavor {
  193.     // here these names are in French
  194.     NOIXDECOCO("CoconutCrepe", 320), AMANDES("AlmondCrepe", 450), POMME("AppleCrepe", 420), SUCREBEURRE(
  195.             "SweetenButterCrepe", 270), MIEL("HoneyCrepe", 280), GRANDMARNIERSUCRE("SweetenGrand-marnierCrepe", 380);
  196.     public String crepename;
  197.     public int price;
  198.     List<String> crepeNames = new ArrayList<String>();
  199.  
  200.     private CrepeFlavor(String crepename, int price) {
  201.         this.crepename = crepename;
  202.         crepeNames.add(crepename);
  203.         this.price = price;
  204.     }
  205.  
  206.     String getName() {
  207.         return crepename;
  208.     }
  209.  
  210.     int getPrice() {
  211.         return price;
  212.     }
  213.  
  214. }
  215.  
  216. ▪️ErrorLog
  217. The left-hand side of an assignment must be a
  218.  variable
  219. type mismatch: cannot convert from IceCreamFlavor to List<IceCreamFlavor>
  220.  
  221. ▪️Execution(executed program result)
  222. Hazelnut
  223. The price of ice-cream is 300 dollars.
  224. WHIPPEDCREAM Amy`s purchased items are [WHIPPEDCREAM].
  225. WHIPPEDCREAM OREOCOOKIECRUMBLES Amy bought [WHIPPEDCREAM, OREOCOOKIECRUMBLES]
  226. ITS TEST
  227. WHIPPEDCREAM
  228. Mawson bought Almond-Ice which was 370 dollars.
  229. OREOCOOKIECRUMBLES ALMOND WHIPPEDCREAM [OREOCOOKIECRUMBLES, ALMOND, WHIPPEDCREAM]
  230. HAZELNUT MARSHMALLOWS What Miley has got? [HAZELNUT, MARSHMALLOWS]
  231. Luise went to FrenchCrepeShop.
  232. Luise bought HoneyCrepe which was 280 dollars.
  233. HoneyCrepe
  234. c5's name is Luise
  235. GRANDMARNIERSUCRE NOIXDECOCO
  236. Sizler
  237. HAZELNUT ALMOND HAZELNUT
Advertisement
Add Comment
Please, Sign In to add comment