Question: Write the required Java code to implement only the two classes BreadDecorator and CheeseDecorator using the decorator pattern. The GetCost() returns the products price. It

  1. Write the required Java code to implement only the two classes BreadDecorator and CheeseDecorator using the decorator pattern. The GetCost() returns the products price. It can be the original price or global price after decoration (after adding cheese or potato). The methods AddCheese() and AddPotato() return the decorations price. The GetDescription() returns the description of the final product (Example: French Bread with cheese).

 Write the required Java code to implement only the two classes

Bread -description : String -cost : Double +GetDescription() :String +GetCost(): Double FrenchBread +GetDescription():String +GetCost(): Double Arabic Bread +GetDescription():String +GetCost(): Double BreadDecorator +GetDescription():String +GetCost(): Double Cheese Decorator +GetDescription():String +GetCost(): Double -AddCheese(): Double Potato Decorator +GetDescription():String +GetCost(): Double -AddPotato() : Double

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!