Class Notebook
- java.lang.Object
-
- Notebook
-
public class Notebook extends java.lang.Object
A class to maintain an arbitrarily long list of notes. Notes are numbered for external reference by a human user. In this version, note numbers start at 0.- Version:
- 2008.03.30
- Author:
- David J. Barnes and Michael Kolling.
-
-
Constructor Summary
Constructors Constructor Description Notebook()
Perform any initialization that is required for the notebook.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addManyNotes(int n)
This method will quickly add a bunch of notes to the notebook for testing purposes.java.util.ArrayList<java.lang.String>
getNotesContaining(java.lang.String term)
Similar to the method above, but collects all of the notes that contain the search term and RETURNS them in a new list.void
listAllNotes()
List all notes in the notebook.void
listAllNotesWithNumber()
List all notes in the notebook, but with numbers in front.void
listLongNotes()
List the notes of length 10 or greater.int
numberOfNotes()
Returns the number of notes in the collection.void
removeNote(int noteNumber)
Remove a note from the notebook if it exists.void
showNote(int noteNumber)
Show a note.void
showNotesContaining(java.lang.String term)
Print the notes in the notebook containing a particular search term.void
storeNote(java.lang.String note)
Store a new note into the notebook.void
storeNoteAtPosition(java.lang.String note, int position)
Store a new note into the notebook.int
totalNoteLengths()
Count up the total length of all notes in the notebook and return it.
-
-
-
Method Detail
-
storeNote
public void storeNote(java.lang.String note)
Store a new note into the notebook.- Parameters:
note
- The note to be stored.
-
storeNoteAtPosition
public void storeNoteAtPosition(java.lang.String note, int position)
Store a new note into the notebook.- Parameters:
note
- The note to be stored.position
- Position at which note should be stored
-
numberOfNotes
public int numberOfNotes()
Returns the number of notes in the collection.- Returns:
- The number of notes currently in the notebook.
-
showNote
public void showNote(int noteNumber)
Show a note.- Parameters:
noteNumber
- The number of the note to be shown.
-
removeNote
public void removeNote(int noteNumber)
Remove a note from the notebook if it exists.- Parameters:
noteNumber
- The number of the note to be removed.
-
listAllNotes
public void listAllNotes()
List all notes in the notebook. We'll call these "for-each loops". The body of the loop runs once for each item in the ArrayList. To the right of : is the ArrayList to "process". To the left is a variable declaration for a variable to hold ONE item from the collection. Java automatically copies each item, in turn, from the list to the local variable and runs the code in the "body".
-
listLongNotes
public void listLongNotes()
List the notes of length 10 or greater.
-
listAllNotesWithNumber
public void listAllNotesWithNumber()
List all notes in the notebook, but with numbers in front.
-
totalNoteLengths
public int totalNoteLengths()
Count up the total length of all notes in the notebook and return it.- Returns:
- The sum of the lengths of the notes.
-
showNotesContaining
public void showNotesContaining(java.lang.String term)
Print the notes in the notebook containing a particular search term.
-
getNotesContaining
public java.util.ArrayList<java.lang.String> getNotesContaining(java.lang.String term)
Similar to the method above, but collects all of the notes that contain the search term and RETURNS them in a new list.- Parameters:
term
- The search term we're looking for- Returns:
- An ArrayList containing the "hits"
-
addManyNotes
public void addManyNotes(int n)
This method will quickly add a bunch of notes to the notebook for testing purposes.- Parameters:
n
- The number of notes I want
-
-