Question: do in java and make sure to test the code with some inputs Suppose that a list can contain items and other lists. Therefore, the

do in java and make sure to test the code with some inputsdo in java and make sure to test the code with some

Suppose that a list can contain items and other lists. Therefore, the composite pattern can perfectly be used to implement such a list. For example, the list: (1 (2 3) (4 5) (6 4)) 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 pro gram structure: ListBuilder + printVa ue0 void + addChild index: int, child: ListComponent) :void- + removeChid index int) void + getChild(index: i +buildCloseBracket) void +buildElementielement: int):VD ListC nent tem value int ListCompo site The program will take an input in the form: (1 (2 3) (4 5) (6 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 printValue0 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 (tokennumber) builder.buildElement(number) ListComponent list builder.getListO list.print Value0 Suppose that a list can contain items and other lists. Therefore, the composite pattern can perfectly be used to implement such a list. For example, the list: (1 (2 3) (4 5) (6 4)) 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 pro gram structure: ListBuilder + printVa ue0 void + addChild index: int, child: ListComponent) :void- + removeChid index int) void + getChild(index: i +buildCloseBracket) void +buildElementielement: int):VD ListC nent tem value int ListCompo site The program will take an input in the form: (1 (2 3) (4 5) (6 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 printValue0 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 (tokennumber) builder.buildElement(number) ListComponent list builder.getListO list.print Value0

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!