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: Suppose that a list

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 implement such a list. For example, the list: [1 [ [ 23 3 [ [4 5 [ [6 4 4] is composed of an item 1 and three lists: 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: The program will take an input in the form: [1 [ [2 3 ] [ [4 5 5 [ [ 6 4 4]] 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!