Ok, I did a little research and found that I can use the instanceof operator to check if the variable that is passed is an instance of the Procedures class. Where do I go from there? Here's the block of code that I'm working with:
/**
* Compare this procedure to the one passed in as an argument.
* Procedures are compared based on their names only - case is
* ignored!
*
* @param other The Procedure object to compare this to.
*
* @return 0 if the names of the two procedures are equal.
* a value < 0 if the name of this procedure is less than the name
* of the procedure passed in.
* a value > 0 if the name of this procedure is greater than the
* name of the procedure passed in.
*/
public int compareTo( Object other ) {
int retint;
if( other instanceof Procedure ) {
String newName = new String( (Procedure)other.getName() );
retint = name.compareToIgnoreCase(other.getName());
}
return retint;
}
The Procedure class represents a medical procedure. I'm writing it as part of a doctor's office simulation for my CS class project. Each procedure , when created, is given a name, a cost, a duration, and two boolean values that tell it whether or not it is covered by HMO Insurance and/or Private Insurance. The compareTo method in Procedure is supposed to compare the Procedure that it is called on with another Procedure that is passed in as an Object. The two Procedures are compared by name only, and case is ignored. It is supposed to return an int value that is either negative (if the first String is less than the second), positive (if the second String is less than the first), or zero (if both Strings are equal).
As far as I can tell, the String method compareToIgnoreCase will do exactly what I need done (ignoring case, return a negative, positive, or zero depending on the two Strings' relationship), once I can get the name of the 'other' Procedure object.
name is the String within this instance of Procedure that I am comparing with the String name of 'other,' which is another Procedure object.
getName() is the method that I am trying to call from within the Procedure class to get it to return the name of the Procedure 'other'. The class implements the interface Comparable, and this is as far as I've gotten. Its a bit of a hodge-podge as it is now, but if anyone could steer me in the right direction I'd appreciate it.