Question: Question posted in first image, Need written in java. 1.3 In the Employee class, modify the toString method so that the gross pay is printed




Question posted in first image, Need written in java.
1.3 In the Employee class, modify the toString method so that the gross pay is printed with a comma to the left of the hundreds digit. For example, if the name is O'Brien, Theresa" and the gross pay is 74400.00, the toString method will return O'Brien, Theresa $74,400.00 import java.text.DecimalFormat; public interface Employee { final static Decimal Format MONEY = new Decimal Format (" $0.00"); // a class constant used in formatting a value in dollars and cents * Returns this Employee object's name. * @return this Employee object's name. */ String getName(); /** Returns this Employee object's gross pay. * * @return 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). * * sk @return a String representation of this Employee object. * String toString(); } // interface Employee import java.text.DecimalFormat; public class FullTime Employee implements Employee { private String name; private double grossPay; * Initializes this FullTime Employee object to have an empty string for the name and 0.00 for the gross pay. * public FullTime Employee() { final String EMPTY_STRING = ""; name = EMPTY_STRING; gross Pay = 0.00; } // default constructor * Initializes this FullTime Employee object's name and gross pay from a a specified name and gross pay. + @param name - the specified name. @param gross Pay - the specified gross pay. * * public Fulltime Employee (String name, double grossPay) { this.name = name; this.grossPay = gross Pay; } // 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 FullTime Employee object. * @return the gross pay of this FullTimeEmployee object. * public double getGrossPay ( ) { return gross Pay; } // method getGross Pay /** * * 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 FullTime Employee
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
