From 01b89d7e77bb23d952227d1cc204be28ef6cd028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Jasi=C5=84ski?= Date: Mon, 11 Oct 2021 19:49:48 +0200 Subject: [PATCH] added meal and meal menu --- src/main/java/products/Meal.java | 23 +++++++++++++++++++++++ src/main/java/products/MealMenu.java | 15 +++++++++++++++ src/main/java/products/main.java | 17 +++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 src/main/java/products/Meal.java create mode 100644 src/main/java/products/MealMenu.java diff --git a/src/main/java/products/Meal.java b/src/main/java/products/Meal.java new file mode 100644 index 0000000..a51bb77 --- /dev/null +++ b/src/main/java/products/Meal.java @@ -0,0 +1,23 @@ +package main.java.products; + +public class Meal implements Product{ + + private final String name; + private final double price; + + public Meal(String aName, double aPrice) { + this.name = aName; + this.price = aPrice; + } + + @Override + public double getPrice() { + return price; + } + + @Override + public String toString() { + return name; + } +} + diff --git a/src/main/java/products/MealMenu.java b/src/main/java/products/MealMenu.java new file mode 100644 index 0000000..60f05b9 --- /dev/null +++ b/src/main/java/products/MealMenu.java @@ -0,0 +1,15 @@ +package main.java.products; + +public class MealMenu extends AbstractMenu { + MealMenu() { + add(new Meal("Pizza", 15.50)); + add(new Meal("Spaghetti", 14.10)); + add(new Meal("Fries", 6.40)); + } + + @Override + protected void showMenuName() { + System.out.println("Meals menu"); + System.out.println("Choose your meal"); + } +} diff --git a/src/main/java/products/main.java b/src/main/java/products/main.java index 4718295..f2f834c 100644 --- a/src/main/java/products/main.java +++ b/src/main/java/products/main.java @@ -56,6 +56,23 @@ public class main { System.out.println("Price: " + orderedSnack.getPrice()); } + private static void orderAMeal() { + MealMenu mealMenu = new MealMenu(); + mealMenu.showMenu(); + int opt; + Meal orderedMeal = null; + while (orderedMeal == null) { + opt = sc.nextInt(); + if (opt < 1 || opt > 4) { + System.out.println("You have chosen wrong option"); + } else { + orderedMeal = mealMenu.get(opt - 1); + } + } + System.out.println("You ordered " + orderedMeal); + System.out.println("Price: " + orderedMeal.getPrice()); + } +