Answer:

It would be nice to let the user enter the String to search for. Further hacks you might consider would allow the user to add and delete Strings in the array.

Phone Number List

But lets do more than that. Let us make this program an (almost) practical application. Our application will search for a name and will then print out that person's phone number. The list of names and phone numbers is implemented as a list of PhoneEntry objects:

class PhoneEntry
{
  String name;    // name of a person
  String phone;   // their phone number

  // constructor
  PhoneEntry( String n, String p )
  {
    name = n; phone = p;
  }
}

The phone number is a String (not an int) because no arithmetic is done with it, and because it may contain colons and dashes. The main() method declares this array:

PhoneEntry[] phoneBook = new PhoneEntry[ 5 ] ;

QUESTION 21:

What exactly does the variable phoneBook look like after this statement?