Breakfast Decorator

Report a typo

They say that breakfast is the most important meal of the day: if that's true, it better be fancy. In this task, we offer you to decorate a slice of bread for your perfect developer's morning. Do not forget about calories!

Sample Input 1:

Sample Output 1:

Cheese on top of Butter on top of Bread. kCal: 290
Jam on top of Butter on top of Bread. kCal: 370
Write a program in Java 17
class TestDrive {
public static void main(String[] args) {
Breakfast bagel = /* write your code here */;
bagel = new Butter(bagel);
bagel = new Cheese(bagel);
System.out.println(bagel.getSummary());

Breakfast bun = /* write your code here */;
bun = new Butter(bun);
bun = new Jam(bun);
System.out.println(bun.getSummary());
}
}

interface Breakfast {
String getDescription();

int getKcal();

default String getSummary() {
return getDescription() + ". kCal: " + getKcal();
}
}

class Bread implements Breakfast {
String description = "Bread";
int kCal = 200;

@Override
public String getDescription() {
return description;
}

@Override
public int getKcal() {
return kCal;
___

Create a free account to access the full topic