Question: This Question must be done in JAVA: Suppose that a list can contain items and other lists. Therefore, the composite pattern can perfectly used to

This Question must be done in JAVA:

This Question must be done in JAVA: Suppose that a list can

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 [6 4]. 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: List Builder List Component + build OpenBracket():void + buildCloseBracket():void + build Elementielement: int) : vo + getList() : ListComponent + printValue():void + addChild(index:int, child : List Component) : void + removeChild(index:int) : void + getChild(index:int): ListComponent 0.- Item -value:int ListComposite The program will take an input in the form: [1 [2 3] [4 5] [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 [2 3], 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. for 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!