Question: java Question#1 Suppose that a list can contain items and other lists. Therefore, the composite pattern can perfectly used to implement such a list. For

java

java Question#1 Suppose that a list can contain items and other lists.

Question#1 Suppose that a list can contain items and other lists. Therefore, the composite pattern can perfectly used to implement such a list. For example, the list: [1 [2 3] [45] [64]] is composed of an item 1 and three lists: [2 3], [4 5] and [64]. In this program you will use Composite pattern and Builder pattern to implement a list structure. The following UML class diagram shows the program structure: ListBuilder ListComponent + buildOpenBracket():void + buildCloseBracket) : void + build Element element: int) : vo +getList(): ListComponent + printValue():void + addChild(index:int child : List Component) : void + removeChild(index:int) : void + getChild(index:int) : ListComponent 0... ListComposite Item |-value: int The program will take an input in the form: [1 [2 3] [45] [64]] and store it using a ListComponent. The program should create a ListComposite and add a child of type Item for 1. Then it will add another child of type ListComposite for [23], in which it will add two Items 2 and 3, and so on. Item's printValue() method only prints out its value. The following is a skeleton code for the main program: ListBuilder builder = new ListBuilder(); read in input list into a string and tokenize it. each token in the input string if (token=="[ builder.buildOpenBracket(); else if (token ==] builder.buildCloseBracket(); else if (token == number) builder.buildElement(number); ListComponent list = builder.getList(); list.printValue()

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!