Pastry packing optimization

Report a typo

You were asked to help with Java programming for a pie company. At the moment, they bake pies, cakes, and tarts and pack them in nice boxes to sell. Unfortunately, their approach to box programming is quite outdated and each pie type requires its own box class. This approach is poorly scalable and will turn the situation into a nightmare with product range growth (imagine all these: ApplePieBox, StrawberryPieBox, etc.).

To avoid this, implement a universal Box class that will accommodate anything with put methods and give it back with get methods.

Write a program in Java 17
/**
Box for cakes
*/
class CakeBox {

private Cake cake;

public void put(Cake cake) {
this.cake = cake;
}

public Cake get() {
return this.cake;
}
}

/**
Box for pies
*/
class PieBox {

private Pie pie;

public void put(Pie pie) {
this.pie = pie;
}

public Pie get() {
return this.pie;
}
}


/**
Box for tarts
*/
___

Create a free account to access the full topic