Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ▪️Customer.java
- public class Customer {
- public IceCreamFlavor icecream;
- public int price;
- private String customerName;
- static String hamper;
- 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;
- }
- String purchase() {
- // not really sure what business do here
- // just return the Ice cream.
- return icecream.getName();
- }
- }
- ▪️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.purchase() + ".");
- c.buy(IceCreamFlavor.OREOCOOKIECRUMBLES);
- System.out.println(c.purchase());
- System.out.println(c.icecream.getName());
- System.out.println(c2.getCustomerName() + " bought " + c2.icecream.getName() + "-Ice"
- + " which was " + c2.icecream.getPrice() + " dollars.");
- }
- }
- ▪️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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment