Lab 4: Using and Understanding Java's Library
Due dates: This is a one week lab, so it will be due
October 16.
Sam will be gone this week(October 9), so Anne will teach both labs. Since the exam is today (Monday),
the first part of the lab will be devoted to going over the questions worked on
in class Friday. The second part of the lab you can begin work on this week's lab.
What to do
- Read carefully Section 4.1 in your text.
- Answer Question #1 under Self-Check on page 200.
- Download LearningToUseArrayLists.java and run the program so you know
exactly what it does.
- Write the two static methods that are stubbed in in that class. (This is
questions #1 and #2 under the Programming section on page 200.)
- Write statements in the main method to test each method.
- Read carefully Section 4.2 in your text.
- Answer Question #1 under Self-Check on page 202.
- Download ArrayListPD.java and look over
the code. It contains stubs for the methods addOrChange, LookupEntry,
removeEntry, and save.
- You will need to implement these methods so that they will
work with an ArrayList<DirectoryEntry>.
- For those of you who like to see other code, here is the code to
accomplish thsese tasks for an ordinary array. We used this code early in the course for the
PhoneDirectory program, it just needs to be changed to use an
ArrayList<DirectoryEntry>.
- For those of you who prefer to code from scratch, there is help for
the first method in you book. The comments should tell you exactly
what needs to be done in the others.
- Write statements in the main method to test each method. To do this, you will need the
DirectoryEntry class.
- Section 4.3 illustrates how the ArrayList class in the Java library is implemented.
Be sure to read it.