Comp 170 Lab 2 - Adding to the Notebook         Sept 13, 2006

Goals

Overview

For this lab you are to take the existing Notebook project and add some features. The existing Notebook is zipped here; save it and open it. You are to extend the constructor, and add the methods indicated below.

The Constructor

I've changed the constructor to add two notes automatically. You are to add another two notes there.

Methods / Loops

You are to provide the following methods to do the indicated things:

1. listReverse(): Like listNotes, but prints the notes in reverse order (with numbers). Start at notes.size()-1, where N=notes.size(), and stop when N=0. Consider this loop pattern:
    N = notes.size() - 1;
    while (N >= 0) {
        ...
        N = N-1;
    }

2. searchNotes(String s): Prints the notes, with number, that contain the given string s as a substring. To check if s is contained in the Nth note, use the library contains() method as follows:
        String note = notes.get(N);
        if ( note.contains(s)  ) {
            // print note
        }

3. totalLength(): Returns (not prints) the total length of all the notes; that is, the sum of the individual note lengths. To get the length of the Nth note, use
    String note = notes.get(N);
    int len = note.length();
(Note that here as in other places, the declarations of variables note and len as String and int respectively are shown on the same lines as the assignments of values, but you are free to separate the two.)

4. longestNote(): Prints the longest note. To find the longest note, you will need a loop with two variables:
        maxlen:    initially 0, the length of the longest note seen so far.
        position:   the number of the longest note.
As you loop through from 0 to notes.size(), if you find a longer note then you update both variables above. 

    String note = notes.get(N);
    if (note.length() > maxlen) {    // longer note found
        maxlen = note.size();
        position = N;
    }
After the completion of the loop, you print out notes.get(position), the note with the given position. Print out its number as well.

Email me your completed project.