labtest1
Class President

java.lang.Object
  extended by labtest1.President

public class President
extends Object

This class represents a president. There can be only a single president (singleton).


Method Summary
 String getFirstName()
          Returns the first name of this president.
static President getInstance(String firstName, String lastName)
          Returns a president with the given first name, last name and no years in office.
static President getInstance(String firstName, String lastName, int numberOfYearsInOffice)
          Returns a president with the given first name, last name and number of years in office.
 String getLastName()
          Returns the last name of this president.
 String getName()
          Returns the name of this president.
 int getNumberOfYearsInOffice()
          Returns the number of years in office of this president.
 void setNumberOfYearsInOffice(int numberOfYearsInOffice)
          Sets the number of years in office of this president to the given number of years in office.
 String toString()
          Returns a string representation of this president.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getFirstName

public String getFirstName()
Returns the first name of this president.

Returns:
the first name of this president.

getLastName

public String getLastName()
Returns the last name of this president.

Returns:
the last name of this president.

getNumberOfYearsInOffice

public int getNumberOfYearsInOffice()
Returns the number of years in office of this president.

Returns:
the number of years in office of this president.

setNumberOfYearsInOffice

public void setNumberOfYearsInOffice(int numberOfYearsInOffice)
Sets the number of years in office of this president to the given number of years in office.

Parameters:
numberOfYearsInOffice - the new number of years in office of this president.
Precondition:
numberOfYearsInOffice >= 0

getName

public String getName()
Returns the name of this president. The name consists of the first name followed by a single space followed by the last name.

Returns:
the name of this president.

getInstance

public static President getInstance(String firstName,
                                    String lastName,
                                    int numberOfYearsInOffice)
Returns a president with the given first name, last name and number of years in office.

Parameters:
firstName - the first name of the president.
lastName - the last name of the president.
numberOfYearsInOffice - the number of years in office.
Precondition:
numberOfYearsInOffice >= 0
Returns:
a president with the given first name, last name and number of years in office.

getInstance

public static President getInstance(String firstName,
                                    String lastName)
Returns a president with the given first name, last name and no years in office.

Parameters:
firstName - the first name of the president.
lastName - the last name of the president.
Returns:
a president with the given first name, last name and no years in office.

toString

public String toString()
Returns a string representation of this president. This representation consists of two lines. The first line consists of the name of this president. The second line a * for each year this president is in office.

Overrides:
toString in class Object
Returns:
a string representation of this president.