1 Data Definition
2 OO style
3 Procedural style
4 Once again with null

Lab 7, CSC 102, Spring 2012

1 Data Definition

Develop the StringList hierarchy, containing the StringList interface, and the SLEmpty and SLPair classes. An SLPair contains a string and a StringList. An SLEmpty contains nothing.

Create a test case class containing at least two examples of string lists.

2 OO style

In the object-oriented style, develop the hasApple method, that returns true for a list containing the string "Apple". Write the test cases before filling in the bodies of the methods.

Follow the template! Make sure you have a recursive call for every self-referential element of the data.

3 Procedural style

In the procedural style, develop the static method hasAppleP in your test class, that returns true for a list containing the string "Apple". That is, it’s exactly the same method, but written in a procedural style. Use "instanceof" to check whether a given StringList is Empty or not. Write the test cases (transliterated from the prior section) before developing the body of the method.

Follow the template! Make sure you have a recursive call for every self-referential element of the data.

4 Once again with null

Now, we’re going to do the same thing with ’null’.

Develop the SNList hierarchy, containing the SNList class, that contains a string and a *possibly null* SNList. Indicate that the field may be null using a comment on the field declaration.

Now, develop the static method hasAppleNP in your test class, that returns true for an SNlist containing the string "Apple."