Question: [Java] [Decorator Pattern] The winter holidays will be here (again) before you know it! Being the organized individual you are, you have a plan for

[Java] [Decorator Pattern]

The winter holidays will be here (again) before you know it! Being the organized individual you are, you have a plan for next year's holiday tree. Implement a software system (from incomplete code) that allows you to calculate the price of any tree plus any combination of decorations. The system must be easily extendable in the sense that whenever new decorations are added in the store you will have to at most add one class.

incomplete code: drive.google.com/drive/folders/1nyAbRB5TRD6BTWyWd_7B5R_rsW71ismw

Here are two tables representing costs of trees and decorations

Costs of trees
Name Cost
Fraser Fir 12
Douglas Fir 15
Balsam Fir 5
Colorado Blue Spruce 20
Costs of decorations
Name Cost
Star 4
Ruffles 1
Balls Red 1
Balls Silver 3
Balls Blue 2
Ribbons 2
Lights 5
LEDs 10

A very important requirement is that a tree can only have one star. When a user wants to decorate a tree with a star with a new star you must print a warning that the tree already has a star and not add the price of a star to a tree. Users must be able to continue decorating their tree if they add another star to it:

Tree mytree = new BlueSpruce(); mytree = new Star(mytree); mytree = new Ruffles(mytree); mytree = new Star(mytree); mytree = new Ruffles(mytree); printtree(mytree); 

should lead to:

Tree already has a star! Blue spruce tree decorated with, a Star, Ruffles, Ruffles costs $26.00 

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!