Constructor

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:

null

Constructor

Ordinarily the data for the phone book would come from a disk file. In this example program, it will be "hard coded" into the constuctor:

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

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

class PhoneBook
{ 
  PhoneEntry[] phoneBook; 

  PhoneBook()    // constructor
  {
    phoneBook = new PhoneEntry[ 5 ] ;

    phoneBook[0] = new PhoneEntry( "James Barclay", "(418) 665-1223" );
    phoneBook[1] = new PhoneEntry( "Grace Dunbar", "(860) 399-3044" );
    phoneBook[2] = new PhoneEntry( "Paul Kratides", "(815) 439-9271" );
    phoneBook[3] = new PhoneEntry( "Violet Smith", "(312) 223-1937" );
    phoneBook[4] = new PhoneEntry( "John Wood", "(913) 883-2874" );

  }

  PhoneEntry search( String targetName )  
  {
    . . . .     // use linear search to find the targetName
  }
}

Let us assume that the array will have every cell filled with a reference to a PhoneEntry object (as is true here.)

QUESTION 23:

Can the linear search algorithm be used on a completely full array?