Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ▪️IceCreamShopMain.java
- import static java.lang.System.*;
- public class IceCreamShopMain {
- public static void main(String[] args) {
- System.out.println(IceCreamFlavor.HAZELNUT.getName());
- System.out.println("The price of ice-cream is " + IceCreamFlavor.HAZELNUT.getPrice() + " dollars.");
- Customer c = new Customer(IceCreamFlavor.WHIPPEDCREAM);
- c.setCustomerName("Amy");
- Customer c2 = new Customer(IceCreamFlavor.ALMOND, "Mawson");
- System.out.println(c.getCustomerName() + "`s purchased items are " + c.printPurchasedIceCreams() + ".");
- c.buy(IceCreamFlavor.OREOCOOKIECRUMBLES);
- System.out.println(c.getCustomerName() + " bought " + c.printPurchasedIceCreams());
- out.println("ITS TEST");
- System.out.println(c.icecream);
- System.out.println(c2.getCustomerName() + " bought " + c2.icecream.getName() + "-Ice" + " which was "
- + c2.icecream.getPrice() + " dollars.");
- Customer c3 = new Customer(IceCreamFlavor.OREOCOOKIECRUMBLES, "Mickey");
- c3.buy(IceCreamFlavor.ALMOND);
- c3.buy(IceCreamFlavor.WHIPPEDCREAM);
- System.out.println(c3.printPurchasedIceCreams());
- Customer c4 = new Customer(IceCreamFlavor.HAZELNUT, "Miley");
- c4.buy(IceCreamFlavor.MARSHMALLOWS);
- out.println("What " + c4.getCustomerName() + " has got? " + c4.printPurchasedIceCreams());
- Customer c5 = new Customer(CrepeFlavor.MIEL, "Luise");
- System.out.println(c5.getCustomerName() + " went to FrenchCrepeShop.");
- out.println(c5.getCustomerName() + " bought " + c5.crepe.getName() + " which was " + c5.crepe.getPrice()
- + " dollars.");
- out.println(c5.crepe.getName());
- out.println("c5's name is " + c5.getCustomerName());
- // [story]Customer Sizler went to the crepe shop.
- Customer c6 = new Customer("Sizler");
- c6.buy(CrepeFlavor.GRANDMARNIERSUCRE);
- c6.buy(CrepeFlavor.NOIXDECOCO);
- c6.printPurchasedCrepes();
- // [story]Customer Sizler went to the ice-cream shop.
- System.out.println(c6.getCustomerName());
- Customer c7 = new Customer(IceCreamFlavor.HAZELNUT);
- c7.buy(IceCreamFlavor.ALMOND);
- c7.printPurchasedIceCreams();
- out.println(c7.getFirstPurchasedIceCreams());
- }
- }
- }
- }
- ▪️Customer.java
- import java.util.*;
- public class Customer {
- public IceCreamFlavor icecream;
- // It is strange for object-oriented that in this Customerfield,
- // declaring a variable "price"
- // Why Customer has already have ice-cream price
- // information?It is strange for object-oriented
- // public int price;
- private String customerName;
- public CrepeFlavor crepe;
- List<IceCreamFlavor> purchasedIceCreams = new ArrayList<IceCreamFlavor>();
- List<CrepeFlavor> purchasedCrepes = new ArrayList<CrepeFlavor>();
- List<IceCreamFlavor> purchasedIceCreams2 = new ArrayList<IceCreamFlavor>();
- Customer(IceCreamFlavor icecream) {
- this.icecream = icecream;
- purchasedIceCreams.add(icecream);
- }
- Customer(IceCreamFlavor icecream, String customerName) {
- this.icecream = icecream;
- purchasedIceCreams.add(icecream);
- this.customerName = customerName;
- }
- Customer(CrepeFlavor crepe) {
- purchasedCrepes.add(crepe);
- }
- Customer(CrepeFlavor crepe, String customerName) {
- this.crepe = crepe;
- purchasedCrepes.add(crepe);
- this.customerName = customerName;
- }
- Customer(String customerName) {
- this.customerName = customerName;
- }
- String getCustomerName() {
- return this.customerName;
- }
- void setCustomerName(String customerName) {
- this.customerName = customerName;
- }
- void buy(IceCreamFlavor icecream) {
- // not really sure what business do here
- // just return the Ice cream.
- // this.icecream = icecream;
- purchasedIceCreams.add(icecream);
- }
- void buy(CrepeFlavor crepe) {
- purchasedCrepes.add(crepe);
- }
- // this method must be changed its name getPurchasedIceCreams()
- List<IceCreamFlavor> printPurchasedIceCreams() {
- for (int i = 0; i < purchasedIceCreams.size(); i++) {
- System.out.print(purchasedIceCreams.get(i));
- System.out.print(" ");
- }
- return purchasedIceCreams;
- }
- void printPurchasedIceCreams3() {
- for (int i = 0; i < purchasedIceCreaams.size(); i++) {
- System.out.print(purchasedIceCreams.get(i));
- }
- }
- IceCreamFlavor getFirstPurchasedIceCreams() {
- // this method which returns the first ice cream
- return purchasedIceCreams.get(0);
- }
- void printPurchasedCrepes() {
- for (CrepeFlavor crepe : purchasedCrepes) {
- System.out.print(crepe + " ");
- }
- System.out.println("");
- }
- // List<IceCreamFlavor> printPurchasedIceCreams2() {
- // for(int i = 0; i < purchasedIceCreams2.size(); i++) {
- // purchasedIceCreams.get(i);
- // }
- // return null;
- // }
- }
- ▪️IceCreamFlavor.java
- import java.util.*;
- enum IceCreamFlavor {
- HAZELNUT("Hazelnut", 300), WHIPPEDCREAM("WhippedCream", 270), ALMOND("Almond",
- 370), OREOCOOKIECRUMBLES("OreoCookieCrumbles", 500), MARSHMALLOWS("Marshmallows", 420);
- public String name;
- public int price;
- List<String> iceCreamNames = new ArrayList<String>();
- private IceCreamFlavor(String name, int price) {
- this.name = name;
- iceCreamNames.add(name);
- this.price = price;
- }
- String getName() {
- return name;
- }
- // List<String> printIceCreamName() {
- //
- // return iceCreamNames.get(i);
- //
- // }
- //
- int getPrice() {
- return price;
- }
- }
- ▪️CrepeFlavor.java
- import java.util.*;
- enum CrepeFlavor {
- // here these names are in French
- NOIXDECOCO("CoconutCrepe", 320), AMANDES("AlmondCrepe", 450), POMME("AppleCrepe", 420), SUCREBEURRE(
- "SweetenButterCrepe", 270), MIEL("HoneyCrepe", 280), GRANDMARNIERSUCRE("SweetenGrand-marnierCrepe", 380);
- public String crepename;
- public int price;
- List<String> crepeNames = new ArrayList<String>();
- private CrepeFlavor(String crepename, int price) {
- this.crepename = crepename;
- crepeNames.add(crepename);
- this.price = price;
- }
- String getName() {
- return crepename;
- }
- int getPrice() {
- return price;
- }
- }
- ▪️ErrorLog
- The left-hand side of an assignment must be a
- variable
- type mismatch: cannot convert from IceCreamFlavor to List<IceCreamFlavor>
- ▪️Execution(executed program result)
- Hazelnut
- The price of ice-cream is 300 dollars.
- WHIPPEDCREAM Amy`s purchased items are [WHIPPEDCREAM].
- WHIPPEDCREAM OREOCOOKIECRUMBLES Amy bought [WHIPPEDCREAM, OREOCOOKIECRUMBLES]
- ITS TEST
- WHIPPEDCREAM
- Mawson bought Almond-Ice which was 370 dollars.
- OREOCOOKIECRUMBLES ALMOND WHIPPEDCREAM [OREOCOOKIECRUMBLES, ALMOND, WHIPPEDCREAM]
- HAZELNUT MARSHMALLOWS What Miley has got? [HAZELNUT, MARSHMALLOWS]
- Luise went to FrenchCrepeShop.
- Luise bought HoneyCrepe which was 280 dollars.
- HoneyCrepe
- c5's name is Luise
- GRANDMARNIERSUCRE NOIXDECOCO
- Sizler
- HAZELNUT ALMOND HAZELNUT
Advertisement
Add Comment
Please, Sign In to add comment