Phone Number List

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

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?