Apply Object-Oriented Programming principles, including encapsulation, inheritance, and…
- User
Apply Object-Oriented Programming principles, including encapsulation, inheritance, and polymorphism, to design and structure your classes.
import java.util.Scanner;
public class Main { public static void main(String[] args) { int menu, bill, quantity, soda, burger, chicken, pasta;
System.out.println("Please select your order."); System.out.println("Main Menu"); System.out.println("Soda press 1"); System.out.println("Burger press 2"); System.out.println("Chicken press 3"); System.out.println("Pasta press 4"); System.out.println(); System.out.println("Enter code from main menu:"); Scanner input = new Scanner(System.in); menu = input.nextInt();
if ((menu <= 0) || (menu >= 5)) { System.out.println("Invalid code! Please check the menu again."); } else if (menu == 1) { System.out.println("Please select: Soda"); System.out.println("Coke: P25 press 1"); System.out.println("Pepsi: P28 press 2"); System.out.println("RC: P26 press 3"); System.out.println(); System.out.println("Enter code from soda menu: "); soda = input.nextInt();
if ((soda <= 0) || (soda >= 4)) { System.out.println("Invalid code! Please check the menu again."); } else { System.out.println("\nPlease enter number of orders: "); quantity = input.nextInt();
if (soda == 1) { bill = quantity * 25; System.out.println("Your bill is " + bill); System.out.println("Please pay at the counter. Thank you & come again!"); } else if (soda == 2) { bill = quantity * 28; System.out.println("Your bill is " + bill); System.out.println("Please pay at the counter. Thank you & come again!"); } else if (soda == 3) { bill = quantity * 26; System.out.println("Your bill is " + bill); System.out.println("Please pay at the counter. Thank you & come again!"); } } } else if (menu == 2) { System.out.println("Please select: Burger"); System.out.println("Regular Burger: P25 press 1"); System.out.println("Cheese Burger: P35 press 2"); System.out.println("Ham & egg Burger: P50 press 3"); System.out.println(); System.out.println("Enter code from Burger menu: "); burger = input.nextInt();
if ((burger <= 0) || (burger >= 4)) { System.out.println("Invalid code! Please check the menu again."); } else { System.out.println("\nPlease enter number of orders: "); quantity = input.nextInt();
if (burger == 1) { bill = quantity * 25; System.out.println("Your bill is " + bill); System.out.println("Please pay at the counter. Thank you & come again!"); } else if (burger == 2) { bill = quantity * 35; System.out.println("Your bill is " + bill); System.out.println("Please pay at the counter. Thank you & come again!"); } else if (burger == 3) { bill = quantity * 50; System.out.println("Your bill is " + bill); System.out.println(“Please pay at the counter. Thank you & come again!”); } } } else if (menu == 3) { System.out.println("Please select: Chicken"); System.out.println("Crispy fried chicken: P60 press 1"); System.out.println("Chicken BBQ: P75 press 2"); System.out.println("Buttered Chicken: P85 press 3"); System.out.println(); System.out.println("Enter code from Chicken menu: "); chicken = input.nextInt();
- Assistant
- User
- Assistant