Lab 5: Strings, Lists, Trees
Part 1: Strings
The goal is to understand how to create new String
objects
and become familiar with some of the methods in the Java String class. String
is a special class - you can define a new String
object
'directly', or by invoking a constructor (see the sample code).
- Download the project with the sample code ( zip or exe).
- Add the code to define a
String
object myPartner
to represent your partner's
name and print this name.
- Add the code to test the length method,
the
charAt
method, and the startsWith
method, using myPartner
object.
- Add the code to test the
compareTo
method
by comparing myPartner
object with the other String
objects myName
and alphabet
)
defined in the sample code.
Part 2: Trees
The goal is to start working with trees.
- Download the project with the sample code ( zip or exe).
- Read the code and draw the UML diagram for the classes
AncestorTree
,
EmptyAncestorTree
, and ConsAncestorTree
.
- Run the code and compare the graphical display with the code. Add
a test case which represents the tree shown in the figure below. The
color of the text for each name is the color of the eyes.
- Develop the method which counts the number of nodes in the AncestorTree.
The UML diagram should help you in creating the template for this method
and its variations.
Ask for help if you do not understand something.