/* CityEntry.java 1.1 */ /* by Sharon Tuttle */ /* last modified: 2-27-03 */ /* (now implements Comparable)*/ abstract class CityEntry implements Comparable { /*------------------------------------ fields -------------------------------------*/ private String name; private String address; private String phone; /*------------------------------------- accessors --------------------------------------*/ String getName() { return this.name; } String getAddress() { return this.address; } String getPhone() { return this.phone; } /*--------------------------------------- modifiers ------------------------------------------*/ void setName(String nm) { this.name = nm; } void setAddress(String addr) { this.address = addr; } void setPhone(String ph) { this.phone = ph; } /*------------------------------------------------ abstract methods (any subclass MUST provide an implementation of!) --------------------------------------------------*/ abstract String specialToString(); abstract String specialGetPhone(); /*----------------------------------------------------------- implementations of interface's abstract methods --------------------------------------------------------------*/ // remember, I want to compare a CityEntry to another CityEntry... public int compareTo(Object obj) { CityEntry entryToCompare = (CityEntry) obj; // what's the name in the passed entryToCompare? String nameToCompare = entryToCompare.getName(); return ( (this.name).compareTo(nameToCompare) ); } /*-------------------------------------- other methods ---------------------------------------*/ /*----------------------------------------------------- isABusiness Purpose: returns true if this item of type CityEntry is a BusinessEntry object --- returns false otherwise. (also serves as a simple example of Java's instanceOf operator) -----------------------------------------------------*/ boolean isABusiness() { if (this instanceof BusinessEntry) { return true; } else { return false; } } }