Practical Exercise 4

    Notebook

  1. Using notebook1 as a starting point, add a method search which takes a String argument and either prints the first note that starts with the string or prints a message indicating that there is no such note.

 /**
     * Display the first note which begins with a given string. Otherwise display the message 
	 * "no such note"
     * @param noteNumber The number of the note to be shown.
     */
   
    public void search(String ss)
    
    {
        boolean found       = false;
        Iterator<String> it = notes.iterator();
        String note;
        while (it.hasNext() && !found)
        {   note = it.next();
            if ( note.startsWith(ss)) 
            {
                System.out.println(note);
                found=true;
            }
           
        }
        if (!found) System.out.println("no such note");
    }