enum

Enum Lab: Pizza Parlor

Create code that allows a pizza parlor to allow customers to order pizzas. Assume the following types of pizza flavors are available:

Plain
Veggie
Mediterranean
Greek
Meat Lovers

Inside your pizza parlor class, create a menu that displays the different pizza types along with a number and allows the customer to select one of the types based on the number. Note that human interfaces should not have menus that start with the number zero. You should start the numbering at one.

Your method should return the pizza type that has been selected by the customer.

You need to write the menu method in such a way that if pizza flavors are added or deleted, your code should continue to work without any changes.

Enum with Constructors and Methods


enum Size {

// enum constants calling the enum constructors

SMALL("The size is small."),

MEDIUM("The size is medium."),

LARGE("The size is large."),

EXTRALARGE("The size is extra large.");


private final String pizzaSize;


// private enum constructor

private Size(String pizzaSize) {

this.pizzaSize = pizzaSize;

}


public String getSize() {

return pizzaSize;

}

}


class Main {

public static void main(String[] args) {

Size size = Size.SMALL;

System.out.println(size.getSize());

}

}




Enum Lab 2: Pizza Parlor Revisited

Create code that allows a pizza parlor to allow customers to order pizzas. Assume the following types of pizza flavors are available:

Plain
Veggie
Mediterranean
Greek
Meat Lovers

Inside your pizza parlor class, create a menu that displays the different pizza types along with a number and allows the customer to select one of the types based on the number. Note that human interfaces should not have menus that start with the number zero. You should start the numbering at one.

Your method should return the following numbers associated with each pizza type:

Plain 7
Veggie 34
Mediterranean 56
Greek 0
Meat Lovers 1

Your code must store these numbers in their associated enums when they are created as part of the enum constructor calls.

One additional feature you need to add is that if the user enters an invalid String as a response, your code should use Exception Handling to avoid printing any errors on the screen.

You need to write the menu method in such a way that if pizza flavors are added or deleted, your code should continue to work without any changes.