Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a java program named Final.java Within the program, implement a class nam

ID: 3694625 • Letter: C

Question

Create a java program named Final.java Within the program, implement a class named Employee and a subclass of Employee named HourlyEmployee. Employee has fields • First • Last • SSN HourlyEmployee has fields • Wage • HoursWorked Create methods to obtain data for each field. Override toString() for each class so that: • Employee returns the First + Last + SSN and • HourlyEmployee returns the Wage + HoursWorked. Space appropriately. In the main() method, construct an instance of each class and fill with your name, a fictitious SSN, wage and hours worked. Call thetoString() methods from each class to print the information you entered.

Explanation / Answer

Program:

class Employee
{
   private String FirstName,LastName;
   private int SSN;
   Employee()
   {
   }
   Employee(String FirstName,String LastName,int SSN)
   {
       this.FirstName=FirstName;
       this.LastName=LastName;
       this.SSN=SSN;
   }
   String getFirstName()
   {
       return FirstName;
   }
   String getLastName()
   {
       return LastName;
   }
   int getSSN()
   {
       return SSN;
   }
   public String toString()
   {
       return FirstName+" "+LastName+" "+String.valueOf(SSN);
   }
  
}
class HourlyEmployee extends Employee
{
   private double Wage,HoursWorked;
   HourlyEmployee(double Wage,double HoursWorked)
   {
       this.Wage=Wage;
       this.HoursWorked=HoursWorked;
      
   }
   double getWage()
   {
       return Wage;
   }
   double getHoursWorked()
   {
       return HoursWorked;
   }
  
   public String toString()
   {
       return String.valueOf(Wage)+" "+String.valueOf(HoursWorked);
   }
}

class Final
{
   public static void main(String[] args)
   {
       Employee emp= new Employee("John","Miller",123);
       HourlyEmployee hourEmp= new HourlyEmployee(28.5,8);
       System.out.println("Employee to string "+emp.toString());
       System.out.println("HourlyEmployee to string "+hourEmp.toString());
   }
}

Output:

Employee to string John Miller 123
HourlyEmployee to string 28.5 8.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote