From 6acdcaffa752e1c686b2e848e1820c4c27c920e4 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 14 Oct 2024 09:39:40 +0200 Subject: [PATCH] added lab6 ex1 --- .../ex1/HellsKitchen.java | 32 +++++++++++++++++ src/lab6_template_method/ex1/MacDonalds.java | 32 +++++++++++++++++ src/lab6_template_method/ex1/Main.java | 11 ++++++ src/lab6_template_method/ex1/Restaurant.java | 36 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 src/lab6_template_method/ex1/HellsKitchen.java create mode 100644 src/lab6_template_method/ex1/MacDonalds.java create mode 100644 src/lab6_template_method/ex1/Main.java create mode 100644 src/lab6_template_method/ex1/Restaurant.java diff --git a/src/lab6_template_method/ex1/HellsKitchen.java b/src/lab6_template_method/ex1/HellsKitchen.java new file mode 100644 index 0000000..3de579c --- /dev/null +++ b/src/lab6_template_method/ex1/HellsKitchen.java @@ -0,0 +1,32 @@ +package lab6_template_method.ex1; + +public class HellsKitchen extends Restaurant { + public HellsKitchen(String name) { + super("HK " + name); + } + + @Override + public void prepareVegetables() { + log("Preparing nice salad"); + } + + @Override + public void prepareMainMenu() { + log("Creating flavorful dish"); + } + + @Override + public void prepareCheese() { + log("Preparing finest cheese"); + } + + @Override + public void prepareDessert() { + log("Giving birth to awesome dessert"); + } + + @Override + public void prepareCoffee() { + log("Brewing the best coffee"); + } +} diff --git a/src/lab6_template_method/ex1/MacDonalds.java b/src/lab6_template_method/ex1/MacDonalds.java new file mode 100644 index 0000000..26fa200 --- /dev/null +++ b/src/lab6_template_method/ex1/MacDonalds.java @@ -0,0 +1,32 @@ +package lab6_template_method.ex1; + +public class MacDonalds extends Restaurant { + public MacDonalds(String name) { + super("McDonalds " + name); + } + + @Override + public void prepareVegetables() { + log("Vegetables ? What's that ?"); + } + + @Override + public void prepareMainMenu() { + log("McChicken incoming"); + } + + @Override + public void prepareCheese() { + log("Hmmm, creamy cheese"); + } + + @Override + public void prepareDessert() { + log("Preparing McFlurry"); + } + + @Override + public void prepareCoffee() { + log("Preparing short and hot coffee"); + } +} diff --git a/src/lab6_template_method/ex1/Main.java b/src/lab6_template_method/ex1/Main.java new file mode 100644 index 0000000..bc131d1 --- /dev/null +++ b/src/lab6_template_method/ex1/Main.java @@ -0,0 +1,11 @@ +package lab6_template_method.ex1; + +public class Main { + public static void main(String[] args) { + Restaurant r1 = new MacDonalds("Sion"); + Restaurant r2 = new HellsKitchen("London"); + + r1.prepareDinner(); + r2.prepareDinner(); + } +} diff --git a/src/lab6_template_method/ex1/Restaurant.java b/src/lab6_template_method/ex1/Restaurant.java new file mode 100644 index 0000000..3021246 --- /dev/null +++ b/src/lab6_template_method/ex1/Restaurant.java @@ -0,0 +1,36 @@ +package lab6_template_method.ex1; + +public abstract class Restaurant { + private String name; + public Restaurant(String name) { + this.name = name; + } + + public final void prepareDinner() { + serveWater(); + prepareVegetables(); + prepareMainMenu(); + prepareCheese(); + prepareDessert(); + prepareCoffee(); + cleanTable(); + } + + protected void log(String msg) { + System.out.println("[" + name + "] " + msg); + } + + protected final void serveWater() { + log("Serving water"); + } + + protected final void cleanTable() { + log("Cleaning table"); + } + + protected abstract void prepareVegetables(); + protected abstract void prepareMainMenu(); + protected abstract void prepareCheese(); + protected abstract void prepareDessert(); + protected abstract void prepareCoffee(); +}