Class AmericanCity

java.lang.Object
  extended by AmericanCity
Direct Known Subclasses:
TripCity

public class AmericanCity
extends java.lang.Object

The AmericanCity class represents a simple city, where the name of the given city, and the state code are stored in private String instance variables. This class is to be used for HW4 . For a complete description, of this assignment go to:

http://www.cs.sunysb.edu/~cse114/hw/HW4.html


This class only performs very basic functions, allowing the altering and retrieving of String variables that represent a city name and state code. In addition, a simple toString method is provided to get a String representation of this object in a neat form.

Author:
  Richard T. McKenna
  Instructor
  CSE 114 - Computer Science I - Fall 2009
  Stony Brook University


Constructor Summary
AmericanCity()
          Default Constructor for AmericanCity, when called it initializes both the city name and the state code to NOWHERE.

Preconditions: The AmericanCity() constructor is called by a program and the result is assigned either to a variable of type AmericanCity or is passed to another method as a parameter of type AmericanCity.

Postconditions: An AmericanCity object is constructed and memory is reserved for use for that object.
AmericanCity(java.lang.String initCity, java.lang.String initStateCode)
          Second Constructor for AmericanCity, when called it initializes both the city and the stateCode to values provided in the parameter list.

Preconditions: This constructor is called by a program and the result is assigned either to a variable of type AmericanCity or is passed to another method as a parameter of type AmericanCity.

Postconditions: An AmericanCity object is constructed and memory is reserved for use for that object.
 
Method Summary
 java.lang.String getCity()
          Accessor method that returns the city String.

Preconditions: this AmericanCity object must be constructed with instance variables properly initialized.

Postconditions: The city instance variable is returned.
 java.lang.String getStateCode()
          Accessor method that returns the state code String.

Preconditions: this AmericanCity object must be constructed with instance variables properly initialized.

Postconditions: The stateCode instance variable is returned.
static boolean isValidStateCode(java.lang.String testStateCode)
          A static method that tests to see whether the testStateCode provided in the paramter list is a valid state code.
 void setCity(java.lang.String changeCity)
          Mutator method that allows the programmer to change the city.

Preconditions: this AmericanCity object must be constructed.

Postconditions: The city instance variable is assigned the value of changeCity.
 void setStateCode(java.lang.String changeStateCode)
          Mutator method that allows the programmer to change the state code.

Preconditions: this AmericanCity object must be constructed.

Postconditions: The stateCode instance variable is assigned the value of changeState, using Upper Case letters.
 java.lang.String toString()
          Method that returns a string that "textually represents" this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AmericanCity

public AmericanCity()
Default Constructor for AmericanCity, when called it initializes both the city name and the state code to NOWHERE.

Preconditions: The AmericanCity() constructor is called by a program and the result is assigned either to a variable of type AmericanCity or is passed to another method as a parameter of type AmericanCity.

Postconditions: An AmericanCity object is constructed and memory is reserved for use for that object. The constructed object's values are initialized such that the city and stateCode instance variables are set to NOWHERE.


AmericanCity

public AmericanCity(java.lang.String initCity,
                    java.lang.String initStateCode)
Second Constructor for AmericanCity, when called it initializes both the city and the stateCode to values provided in the parameter list.

Preconditions: This constructor is called by a program and the result is assigned either to a variable of type AmericanCity or is passed to another method as a parameter of type AmericanCity.

Postconditions: An AmericanCity object is constructed and memory is reserved for use for that object. The constructed object's city variable is initialized to the initCity value passed to the method and the stateCode variable is initialized to the initStateCode value passed to the method.

Parameters:
initCity - The String value used to initialize the city of the specified AmericanCity.
initStateCode - The String value used to initialize the state code of the specified AmericanCity.
Method Detail

getCity

public java.lang.String getCity()
Accessor method that returns the city String.

Preconditions: this AmericanCity object must be constructed with instance variables properly initialized.

Postconditions: The city instance variable is returned.

Returns:
The String representing the city for the specified AmericanCity.

getStateCode

public java.lang.String getStateCode()
Accessor method that returns the state code String.

Preconditions: this AmericanCity object must be constructed with instance variables properly initialized.

Postconditions: The stateCode instance variable is returned.

Returns:
The String representing the state code for the specified AmericanCity.

setCity

public void setCity(java.lang.String changeCity)
Mutator method that allows the programmer to change the city.

Preconditions: this AmericanCity object must be constructed.

Postconditions: The city instance variable is assigned the value of changeCity.

Parameters:
changeCity - The String value to be used to set the city for the specified AmericanCity.

setStateCode

public void setStateCode(java.lang.String changeStateCode)
Mutator method that allows the programmer to change the state code.

Preconditions: this AmericanCity object must be constructed.

Postconditions: The stateCode instance variable is assigned the value of changeState, using Upper Case letters.

Parameters:
changeStateCode - The String value to be used to set the state code for the specified AmericanCity.

toString

public java.lang.String toString()
Method that returns a string that "textually represents" this object.
Preconditions: this AmericanCity object must be constructed.

Postconditions: A String is returned that represents the values of the city and stateCode instance variables separated by a comma and space, similar to the way city and state are normally represented.

Overrides:
toString in class java.lang.Object
Returns:
A textual representation of the specified AmericanCity.

isValidStateCode

public static boolean isValidStateCode(java.lang.String testStateCode)
A static method that tests to see whether the testStateCode provided in the paramter list is a valid state code.
Preconditions: this method is called statically as in AmericanCity.isValidStateCode(someString), where someString is a value of type String.

Postconditions: If testStateCode String represents a valid state code, true is returned, otherwise false is returned. Note that testStateCode may be provided in lower or upper case letters.

Parameters:
testStateCode - A String value to be tested to see if it represents a valid state code.
Returns:
Whether the testStateCode is valid (true) or not (false).