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

Create a class Employee, which has three private class variables (Name, Address,

ID: 3660880 • Letter: C

Question

Create a class Employee, which has three private class variables (Name, Address, PhoneNumber), access methods to get and set each of these properties, and two constructors (one 0-argument constructor and the second setting property values to specific values passed to the constructor). Create a class SalaryEmployee, which extends Employee and adds one more property (Salary) with proper set and get methods. Add one more method ByWeeklyPay of type double. Create a class HourlyEmployee, which extends Employee and adds two more properties (HourWage and HoursWorked) with relevant get and set methods. Add one more getPayAmount method. Create a class UseEmployee, which will instantiate objects of each of the classes above (Employee, SalaryEmployee, HourlyEmployee) with particular values (take any values of the proper data type) and display the information on all properties of an Employee object created, a SalaryEmployee object created, and an HourlyEmployee object created.

Explanation / Answer

Employee

public class Employee {
   
    private String name;
    private String Address;
    private String phoneNumber;
   
   
    public Employee() {
        super();
    }
   
    public Employee(String name, String address, String phoneNumber) {
        super();
        this.name = name;
        Address = address;
        this.phoneNumber = phoneNumber;
    }
   
   

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAddress() {
        return Address;
    }
    public void setAddress(String address) {
        Address = address;
    }
    public String getPhoneNumber() {
        return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
   
   
}

SalaryEmployee


public class SalaryEmployee extends Employee {
    private double salary;

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }
    public double byWeeklyPay() {
        return salary/4;
    }
}

HourlyEmployee


public class HourlyEmployee extends Employee {
    private double hourWage;
    private double hourWorked;
    public double getHourWage() {
        return hourWage;
    }
    public void setHourWage(double hourWage) {
        this.hourWage = hourWage;
    }
    public double getHourWorked() {
        return hourWorked;
    }
    public void setHourWorked(double hourWorked) {
        this.hourWorked = hourWorked;
    }
   
    public double getPayAmount() {
        return hourWorked * hourWage;
    }
}

UseEmployee



public class UseEmployee {

    /**
    * @param args
    */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Employee e = new Employee("John", "13th main, Washington, USA", "001-123456");
       
        SalaryEmployee se = new SalaryEmployee();
        se.setSalary(35000);
       
        HourlyEmployee he = new HourlyEmployee();
        he.setHourWage(10);
        he.setHourWorked(8);
       
        //using SalaryEmployee instance 'e'
        System.out.println(e.getName() + " "+ e.getAddress() + " " + e.getPhoneNumber());
        //using Employee instance 'se'
        System.out.println("Total Sal: " + se.getSalary() + " Weekly Pay "+ se.byWeeklyPay());
        //using HourlyEmployee instance 'he'
        System.out.println("hour wage: " + he.getHourWage() + " Hours Worked" + he.getHourWorked() + " Payment: " + he.getPayAmount());
    }

}

Output:

John 13th main, Washington, USA 001-123456
Total Sal: 35000.0 Weekly Pay 8750.0
hour wage: 10.0 Hours Worked8.0 Payment: 80.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