Exercise 4.11 public void showNote(int noteNumber) { if(noteNumber < 1) { // This is not a valid note number, so do nothing. } else if(noteNumber <= numberOfNotes()) { // This is a valid note number, so we can print it. System.out.println(notes.get(noteNumber)); } else { // This is not a valid note number, so do nothing. } }
public void removeNote(int noteNumber) { if(noteNumber < 1) { // This is not a valid note number, so do nothing. } else if(noteNumber <= numberOfNotes()) { // This is a valid note number. notes.remove(noteNumber); } else { // This is not a valid note number, so do nothing. } }
public void listNotes()
{
int index = 0;
while(index < notes.size()) {
System.out.println((index+1) + ": " + notes.get(index));
index++;
}
} |