edu.colorado.simulations
Class SocialSecurityNumber

java.lang.Object
  extended by edu.colorado.simulations.SocialSecurityNumber
All Implemented Interfaces:
java.lang.Comparable

public class SocialSecurityNumber
extends java.lang.Object
implements java.lang.Comparable

A SocialSecurityNumber object holds the value of a single social security number. The methods of this class could be expanded to make the class more useful, but I have kept things basic to focus on how to implement the Comparable interface.

Note: A social security number is a nine-digit number broken into three groups in the form XXX-XX-XXXX. The first three digits (the "area") are between 001 and 799 (inclusive). The next two digits (the "group") are between 01 and 99 (inclusive). The last four digits (the "serial") are between 0001 and 9999 (inclusive).

See Also:
Java Source Code for this class (www.cs.colorado.edu/~main/edu/colorado/simulations/SocialSecurityNumber.java) ,
Constructor Summary
SocialSecurityNumber(int n)
          Construct a SocialSecurityNumber from a specified number.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compare this SocialSecurityNumber to another.
 void set(int n)
          Set the value of this SocialSecurityNumber.
 java.lang.String toString()
          Return the value of this Social Security Number as a String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SocialSecurityNumber

public SocialSecurityNumber(int n)
Construct a SocialSecurityNumber from a specified number.

Parameters:
n - the social security number as an integer
Postcondition:
This SocialSecurityNumber has been created and initialized to n.
Method Detail

compareTo

public int compareTo(java.lang.Object o)
Compare this SocialSecurityNumber to another.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the other SocialSecurityNumber to compare to.
Returns:
The return value is a positive number if my number is bigger than the other Object's number. The return value will be zero if my number is the same as the other's number. The return value will be a negative number if my number is smaller than the other's number.
Throws:
java.lang.ClassCastException - Indicates that o is not a SocialSecurityNumber.

set

public void set(int n)
Set the value of this SocialSecurityNumber.

Postcondition:
This SocialSecurityNumber has been initialized to n.

toString

public java.lang.String toString()
Return the value of this Social Security Number as a String.

Overrides:
toString in class java.lang.Object
Returns:
For a valid Social Security Number, the return value is a string of eleven characters with nine digits and two dashes in the format XX-XXX-XXXX. For an invalid Social Security Number, the return value is the string "InvalidSSN".