Answer to Question #254500 in Java | JSP | JSF for hatipo

Question #254500

Problem description Caf´e Wafflelicious, as its very name signifies, is a cafe that sells waffles. When customers arrive at this cafe, they design the waffle they want according to the kinds of waffles, their ingredients and their prices. The waitress delivers these orders to the cook from the customer. The cook is responsible for making the waffle. You will prepare an order system in which you will check the company’s waffle orders.For example, there is a waffle order from the customer. You need to expand the functionality of the class in a transparent and dynamic way.Waffle Types (Concrete component): Normal Waffle - $13.0 Belgian Waffle - $16.0 Wrap Waffle - $13.0 Wheat Waffle - $15.0 1 Free Gluten Waffle - $17.0 Toppings (Concrete decorator): chocolate - $2.0 for each (white, milky, dark, nutella and caramel) fruits - $0.5 for each (strawberry, kiwi, pineapple and banana) sauces - $1.0 for each (chocolate, caramel and raspberry) nuts - $1.0 for each (pistachio, almond, hazelnut and walnut)


1
Expert's answer
2021-10-21T07:23:00-0400




abstract class BaseWaffle {
	String description = "";
	public double price;


	public String getDescription() {


		return description;
	}


	public double getPrice() {
		return price;
	}
}


class BelgianWaffle extends BaseWaffle {


	public BelgianWaffle() {


		this.description = "Belgian waffle dough";
		this.price = 16.0;
	}
}


class FreeGlutenWaffle extends BaseWaffle {


	public FreeGlutenWaffle() {
		this.description = "Free gluten waffle dough";
		this.price = 17.0;
	}
}


class NormalWaffle extends BaseWaffle {


	public NormalWaffle() {
		this.description = " default waffle dough ";
		this.price = 13.0;
	}
}


class WheatWaffle extends BaseWaffle {


	public WheatWaffle() {
		this.description = "waffle dough with wheat flour";
		this.price = 15.0;
	}
}


class WrapWaffle extends BaseWaffle {


	public WrapWaffle() {
		this.description = "Wrap waffle dough";
		this.price = 18.0;
	}
}


abstract class BaseDecorator extends BaseWaffle {


	@Override
	public String getDescription() {
		return super.getDescription();
	}
}


abstract class BaseChocolate extends BaseDecorator {


	public BaseWaffle baseWaffle;


	public BaseChocolate(BaseWaffle waffleToDecorate) {
		this.baseWaffle = waffleToDecorate;
	}


	@Override
	public String getDescription() {
		return super.getDescription();
	}


	@Override
	public double getPrice() {
		return (this.baseWaffle.getPrice() + this.price);
	}
}


class Caramel extends BaseChocolate {


	public Caramel(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 2.0;
	}


	public String getDescription() {


		return baseWaffle.getDescription() + ", Caramel ";
	}
}


class DarkChocolate extends BaseChocolate {


	public DarkChocolate(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 2.0;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Dark Chocolate ";
	}
}


class MilkyChocolate extends BaseChocolate {


	public MilkyChocolate(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 2.0;
	}


	public String getDescription() {


		return baseWaffle.getDescription() + ", Milky Chocolate ";
	}
}


class WhiteChocolate extends BaseChocolate {


	public WhiteChocolate(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 2.0;
	}


	public String getDescription() {


		return baseWaffle.getDescription() + ", White Chocolate ";
	}
}


class Nutella extends BaseChocolate {


	public Nutella(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 2.0;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Nutella ";
	}


}


abstract class BaseFruit extends BaseDecorator {


	public BaseWaffle baseWaffle;


	public BaseFruit(BaseWaffle waffleToDecorate) {
		this.baseWaffle = waffleToDecorate;
	}


	@Override
	public String getDescription() {
		return super.getDescription();
	}


	@Override
	public double getPrice() {
		return (this.baseWaffle.getPrice() + this.price);
	}
}


class Kiwi extends BaseFruit {


	public Kiwi(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 0.5;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Kiwi ";
	}
}


class Banana extends BaseFruit {


	public Banana(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 0.5;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Banana  ";
	}
}


class Pineapple extends BaseFruit {


	public Pineapple(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 0.5;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Pineapple ";
	}
}


class Strawberry extends BaseFruit {


	public Strawberry(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 0.5;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Strawberry ";
	}


}


abstract class BaseNuts extends BaseDecorator {


	public BaseWaffle baseWaffle;


	public BaseNuts(BaseWaffle waffleToDecorate) {
		this.baseWaffle = waffleToDecorate;
	}


	@Override
	public String getDescription() {
		return super.getDescription();
	}


	@Override
	public double getPrice() {
		return (this.baseWaffle.getPrice() + this.price);
	}
}


class Almond extends BaseNuts {


	public Almond(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 1.00;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Almond  ";
	}
}


class Coconut extends BaseNuts {


	public Coconut(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 1.00;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Coconut ";
	}
}


class Hazelnut extends BaseNuts {


	public Hazelnut(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 1.00;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Hazelnut ";
	}
}


class Walnut extends BaseNuts {


	public Walnut(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 1.00;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Walnut ";
	}
}


abstract class BaseSauce extends BaseDecorator {


	public BaseWaffle baseWaffle;


	public BaseSauce(BaseWaffle waffleToDecorate) {
		this.baseWaffle = waffleToDecorate;
	}


	@Override
	public String getDescription() {
		return super.getDescription();
	}


	@Override
	public double getPrice() {
		return (this.baseWaffle.getPrice() + this.price);
	}
}


class CaramelSauce extends BaseSauce {


	public CaramelSauce(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 1.00;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Caramel Sauce ";
	}
}


class ChocolateSauce extends BaseSauce {


	public ChocolateSauce(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 1.00;
	}


	public String getDescription() {
		return baseWaffle.getDescription() + ", Chocolate Sauce ";
	}
}


class RaspberrySauce extends BaseSauce {


	public RaspberrySauce(BaseWaffle waffleToDecorate) {
		super(waffleToDecorate);
		this.price = 1.00;
	}


	public String getDescription() {


		return baseWaffle.getDescription() + ", Raspberry Sauce ";
	}
}


public class App {
	/**
	 * The start point of the program
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// Create first waffle


		BaseWaffle waffle1 = new BelgianWaffle();
		System.out.println(waffle1.getDescription() + " $" + waffle1.getPrice());


		// Now we add some condiment
		waffle1 = new Nutella(waffle1);
		System.out.println(waffle1.getDescription() + " $ " + waffle1.getPrice());


		waffle1 = new ChocolateSauce(waffle1);
		System.out.println(waffle1.getDescription() + " $ " + waffle1.getPrice());


		waffle1 = new Kiwi(waffle1);
		System.out.println(waffle1.getDescription() + " $ " + waffle1.getPrice());


		// Create second waffle


		BaseWaffle waffle2 = new WrapWaffle();
		System.out.println(waffle2.getDescription() + " $ " + waffle2.getPrice());


		waffle2 = new WhiteChocolate(waffle2);
		System.out.println(waffle2.getDescription() + " $ " + waffle2.getPrice());


		waffle2 = new CaramelSauce(waffle2);
		System.out.println(waffle2.getDescription() + " $ " + waffle2.getPrice());


		waffle2 = new Strawberry(waffle2);
		System.out.println(waffle2.getDescription() + " $ " + waffle2.getPrice());


		waffle2 = new Banana(waffle2);
		System.out.println(waffle2.getDescription() + " $ " + waffle2.getPrice());


		waffle2 = new Almond(waffle2);
		System.out.println(waffle2.getDescription() + " $ " + waffle2.getPrice());


		// create third waffle


		BaseWaffle waffle3 = new FreeGlutenWaffle();
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


		waffle3 = new DarkChocolate(waffle3);
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


		waffle3 = new MilkyChocolate(waffle3);
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


		waffle3 = new RaspberrySauce(waffle3);
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


		waffle3 = new Strawberry(waffle3);
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


		waffle3 = new Pineapple(waffle3);
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


		waffle3 = new Kiwi(waffle3);
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


		waffle3 = new Coconut(waffle3);
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


		waffle3 = new Walnut(waffle3);
		System.out.println(waffle3.getDescription() + " $ " + waffle3.getPrice());


	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS