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

Design a class named Employee. The class should keep the following information i

ID: 3625490 • Letter: D

Question

Design a class named Employee. The class should keep the following information in member variables.
• Employee name
• Employee number
• Hire date
Write a constructor that takes above three data members as parameters at the time of object creation. Also, implement the toString method that returns the Employee name and the Hire date.

Then, write a class named ProductionWorker that is derived from the Employee class above. ProductionWorker class should have member variables to hold the following information.
• Hourly pay rate
• Hours worked.

Write a constructor that takes the Employee name, Employee number, hire date and the hourly rate as parameters at the time of ProductionWorker object instance creation.

This constructor should call the Employee constructor to set values of Employee name, Employee number, hire date (see the modified Rectangle class example discussed in the class).

Also, write a methods that sets the hours worked, and compute the salary.
Override the toString method that returns the Employee name , Hire date, and salary.


Your Employee and ProductionWorker classes should work with the Driver program (Assignment7.java) given .


Assignment7.java program should produce the following output

Employee Name: John
Hire Date: 10-12-2008
Salary : $85.00

Explanation / Answer

import java.io.*;

import java.util.Scanner;

class Employee

{

     //fields

     private String Empname;

     private String Empnumber;

     private String Hiredate;

     // default constructor

     public Employee()

     {

          Empname=" ";

          Empnumber=" ";

          Hiredate=" ";     

     }

     //parameterized constructor

     public Employee(String Empname,String Empnumber,

                                        String Hiredate)

     {

          setName(Empname);

          setNumber(Empnumber);

          setHireDate(Hiredate);

     }

     //Mutator functions

     //sets employee name

     public void setName(String n)

     {

          Empname = n;

     }

     //sets employee number

     public void setNumber(String num)

     {

          Empnumber = num;

     }

     //sets hire date

     public void setHireDate(String h)

     {

          Hiredate = h;

     }

     /* Accessor functions */

     //returns employee name

     public String getName()

     {

          return Empname;

     }

     //returns employee number

     public String getNumber()

     {

          return Empnumber;

     }

     //returns hire date

     public String getHireDate()

     {

          return Hiredate;

     }

}

class ProductionWorker extends Employee

{

     //fields

     private int shift;

     private double hourpayrate;

  

     //constructor

     public ProductionWorker(String Empname,

                              String Empnumber,

                         String Hiredate,int shift,

                                   double hourpayrate)

     {

          super(Empname,Empnumber,Hiredate);

          setShift(shift);

          setHourlyPayRate(hourpayrate);

     }

  

  

     //accessor

     public int getShift()

     {

          return shift;

     }

  

     public double getHourlyPayRate()

     {

          return hourpayrate;

     }

  

  

     //mutator

     public void setShift(int s)

     {

          shift = s;

     }

  

     public void setHourlyPayRate(double r)

     {

          hourpayrate = r;

     }

      

}

public class EmployeeDemo

{

     public static void main(String[] args)

     {

         String name,id,date;

         double pay;

         int shift;

        //create scanner object

         Scanner keyboard= new Scanner(System.in);

         //inputing data

         System.out.println("Enter employee name:");

         name=keyboard.nextLine();

          //inputting ID

        System.out.println("Enter employee ID: ");

        id=keyboard.nextLine();

          //inputting date

         System.out.println("Enter employee Date: ");

         date=keyboard.nextLine();

         //inputting shift

          System.out.println("1-Day Shift 2-Night shift");

          System.out.println("Enter employee Shift: ");

          shift=keyboard.nextInt();

          //inputting pay

          System.out.println("Enter hourly pay:");

          pay=keyboard.nextDouble();

          //instantiating worker       

          ProductionWorker pw =

              new ProductionWorker(name,id,date,shift,pay);

        //outputting data using accessor methods

     System.out.println("Employee Name:"+pw.getName());

     System.out.println("Employee ID:"+ pw.getNumber());

     System.out.println("Hire Date:"+pw.getHireDate());

     System.out.println("Shift:"+pw.getShift());

     System.out.println("Hourly Rate:"

                               +pw.getHourlyPayRate());

     }//end main

}

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