A good answer might be:

The complete search() follows:

Completed Search

Here is the completed search() method.

  PhoneEntry search( String targetName )  
  {
    for ( int j=0; j < phoneBook.length; j++ )
    {
      if ( phoneBook[ j ].name.equals( targetName ) )
        return phoneBook[ j ];
    }

    return null;
  }

You may be uncomfortable with this expression:

  phoneBook[ j ].name.equals( targetName )

Look at it piece by piece:

  • phoneBook[ j ] contains a reference to a PhoneEntry object.
  • The PhoneEntry object contains an instance variable name.
  • name is a reference to a String object.
  • One of the methods all String objects have is the equals() method.
  • Use this equals() method with another String referred to by targetName .
  • The entire expression evaluates to true or false.

This is fairly complicated, and if you are still uncomfortable don't worry too much. But you probably won't like the question.

QUESTION 21:

Does the expression

  targetName.equals( phoneBook[ j ].name )
do the same thing as the above expression?

Click Here after you have answered the question