A good answer might be:

It will be useful to have an equals() method which indexOf() will use, and it will be useful to override the toString() method.


Complete Entry

You may have thought of some methods like setName() and setNumber() that would be useful in a more realistic example. But let us stop with just two methods.

class Entry
{
  String name;
  String number;

  // constructor
  Entry( String n, String num )
  {
    name = n; number = num;
  }

  // methods
  public boolean equals( Object other )
  {
    return name.equals( ((Entry)other).name );
  }

  public String toString()
  {
    return "Name: " + name + " Number: " + number;
  }
 
}

The toString() method overrides the toString() method that all objects have. Our method returns a more useful string than the inherited method.

QUESTION 20:

What does the following code write?

Entry ent = new Entry( "Amy", "123-4567");

System.out.println( ent );