import java.util.*; // for StringTokenizer class import java.text.DecimalFormat; public class FullTimeEmployee implements Employee { protected String name; protected double grossPay; /** * Initializes this FullTimeEmployee object to have an empty string for the * name and 0.00 for the gross pay. * * */ public FullTimeEmployee() { final String EMPTY_STRING = ""; name = EMPTY_STRING; grossPay = 0.00; } // default constructor /** * Initializes this FullTimeEmployee object’s name and gross pay from a * a specified String object, which consists of a name and gross pay, with at * least one blank in between. * * @param s - the String object from which this FullTimeEmployee object * is initialized. * */ public FullTimeEmployee (String s) { StringTokenizer tokens = new StringTokenizer (s); name = tokens.nextToken(); grossPay = Double.parseDouble (tokens.nextToken()); } // constructor with String parameter /** * Determines if this Employee object’s gross pay is greater than * a specified Employee object’s gross pay. * * @param otherEmployee - the specified Employee object whose * gross pay this Employee object’s gross pay is compared to. * * @return true - if otherEmployee is a FullTimeEmployee object, and * the calling object’s gross pay is greater than * otherEmployee’s gross pay. Otherwise, return false. * */ public boolean makesMoreThan (Employee otherEmployee) { if (!(otherEmployee instanceof FullTimeEmployee)) return false; FullTimeEmployee full = (FullTimeEmployee)otherEmployee; return grossPay > full.grossPay; } // method makesMoreThan /** * Returns a String representation of this Employee object with the name * followed by a space followed by a dollar sign followed by the gross * monthly pay, with two fractional digits. * * @return a String representation of this Employee object. * */ public String toString() { final String DOLLAR_SIGN = " $"; DecimalFormat d = new DecimalFormat ("0.00"); return name + DOLLAR_SIGN + d.format (grossPay); } // method toString } // class FullTimeEmployee