Template Method

Report a typo

There are two classes: an abstract class Meal with the template method and a concrete class Steak

Every meal is different, but the common algorithm is known.

You must implement the template method in Meal class to cook a meal with the following approach:

  • Prepare the ingredients;
  • Cook the meal;
  • Enjoy the meal;
  • Wash the dishes after the meal.

Please, do not change the provided code of the classes.

Sample Input 1:

Mike

Sample Output 1:

Mike wants to eat
Mike decides to cook meal
Ingredients: beef steak, lemon, olive oil, salt, sugar
Fry the steak in the pan
That's good
Push dishes in the sink and go coding
Write a program in Java 17
import java.util.Scanner;

abstract class Meal {

/**
* It provides template method of meal routine.
*/
public void doMeal() {
// write your code here ...
}

public abstract void prepareIngredients();

public abstract void cook();

public void eat() {
System.out.println("That's good");
}

public abstract void cleanUp();
}

class Steak extends Meal {

@Override
public void prepareIngredients() {
System.out.println("Ingredients: beef steak, lemon, olive oil, salt, sugar");
}

@Override
public void cook() {
System.out.println("Fry the steak in the pan");
}

@Override
public void cleanUp() {
___

Create a free account to access the full topic