Question: This exercise presents an alternative to having protected fields. Modify the FullTimeEmployee class as follows: Change the visibility of the name and grossPay fields from



This exercise presents an alternative to having protected fields. Modify the FullTimeEmployee class as follows: Change the visibility of the name and grossPay fields from protected to private, and develop public methods to get and set the values of those fields. A method that alters a field in an object is called a mutator, and a method that returns a copy of a field is called an accessor. Here are the method specifications corresponding to the name field: /** Returns this FullTimeEmployee object's name. @return a (reference to a) copy of this FullTimeEmployee object's name. */ public String getName /** Sets this FullTimeEmployee object's name to a specifed string. @param nameIn - the String object whose value is assigned to this FullTimeEmployee object's name. public void setName (String nameIn) import java. text.DecimalFormat; public interface Employee che bns ecyT sied foedadA Ginal static DecimalFormat MONEY = new DecimalFormat (" $0.00*); // a class constant used in formatting a value in dollars and cents /** Returns this Employee object's name. Areturn this Employee object's name, String getName (); Returns this Employee object's gross pay. ereturn this Employee object's gross pay. double getGrossPay(); Returns a String representation of this Employee object with the name followed by a space followed by a dollar sign followed by the gross weekly pay, with two fractional digits (rounded). @return a String representation of this Employee object. */ String toString (); }// interface Employee sections of this import java.text.DecimalFormat; public elass FullTimeEmployee implements Employee private String name; private double grossPay: Tnitializes 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 name and gross pay. Oparam name @param gross Pay - the specified gross pay. - the specified name. public FullTimeEmployee (String name, double grocaPay) this.name name; this.grossPay grossPay; ) // 2-parameter constructor /** Returns the name of this FullTimeEmployee object. @return the name of this FullTimeEmployee object. */ public String getName () return name; } // method getName Returns the gross pay of this FullTimeEmployee object. Greturn the gross pay of this FullTimeEmployee object. */ public double getGrossPay () return grossPay; }// method getGrossPay /** Returns a String representation of this FullTimeEmployee object with the name followed by a space followed by a dollar sign followed by the gross weekly pay, with two fractional digits (rounded), followed by "FULL TIME" @return a String representation of this FullTimeEmployee object. public String toString () final String EMPLOYMENT_STATUS = "FULL TIME"; return name + MONEY.format (grossPay) + EMPLOYMENT_STATUS; // the format method returns a String representation of grossPay. ) // method tostring } // class FullTimeEmployee
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
