Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ▪️IceCreamShopMain.java
- 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.printPurchasedIceCreams());
- System.out.println(c.icecream.getName());
- 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.java
- import java.util.*;
- public class Customer {
- public IceCreamFlavor icecream;
- public int price;
- private String customerName;
- static String hamper;
- List<IceCreamFlavor> purchasedIceCreams = new ArrayList<IceCreamFlavor>();
- Customer(IceCreamFlavor icecream) {
- this.icecream = icecream;
- }
- Customer(IceCreamFlavor icecream, String customerName) {
- this.icecream = icecream;
- this.customerName = customerName;
- }
- // String getName() {
- // return icecream.getName();
- // }
- //
- // int getPrice() {
- // return icecream.getPrice();
- // }
- 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);
- }
- IceCreamFlavor printPurchasedIceCreams() {
- // not really sure what business do here
- // just return the Ice cream.
- for(int i = 0; i < purchasedIceCreams.size(); i++) {
- purchasedIceCreams.get(i);
- return purchasedIceCreams.get(i);
- }
- }
- }
- ▪️IceCreamFlavor.java
- enum IceCreamFlavor {
- HAZELNUT("Hazelnut", 300), WHIPPEDCREAM("WhippedCream", 270), ALMOND("Almond",
- 370), OREOCOOKIECRUMBLES("OreoCookieCrumbles", 500), MARSHMALLOWS("Marshmallows", 420);
- public String name;
- public int price;
- private IceCreamFlavor(String name, int price) {
- this.name = name;
- this.price = price;
- }
- String getName() {
- return name;
- }
- int getPrice() {
- return price;
- }
- }
- ▪️Error Log
- Exception in thread "main" java.lang.Error: Unresolved compilation problem:
- This method must return a result of type IceCreamFlavor
- at Customer.printPurchasedIceCreams(Customer.java:45)
- at IceCreamShopMain.main(IceCreamShopMain.java:8)
- This method must return a result of type
- IceCreamFlavor
Advertisement
Add Comment
Please, Sign In to add comment