Vector Exercise


instance variables:

methods:


// locate Person in a vector and return the index
private int locatePerson ( String searchSSN ) 
{
     int index = -1;               // initialize to one less than smallest index
     boolean found = false;

     while ( !found && ++index < personVect.size( ) ) 
     {
          found = searchSSN.equals ( ((Person) personVect.elementAt(index)).getSSN ( ) );
     }

     if (found) return index;
     else return -1;
} // end locatePerson

 


 

public class Person 
{
     private String name;
     private String SSN;
     private String address;

     public Person ( ) 
     {
          name = " ";
          SSN = "000-00-0000";
          address = " ";
     }

     public Person ( String name, String SSN, String address ) 
     {
          this.name = name;
          this.SSN = SSN;
          this.address = address;
     }

     public String getSSN ( ) 
     {
          return SSN;
     }

     // Return String with values of instance variables
     public String showPerson( )
     {
          return "" + name + " with SSN " + SSN + " lives at " + address;
     } // end showPerson
}

 

 

 

 

 

 

 

 

 

 

  .