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

1. Create a package called hrInterface. Define an interface Payable with a calcP

ID: 3703376 • Letter: 1

Question

1. Create a package called hrInterface. Define an interface Payable with a calcPayroll method in the package.

2. Create another package called employee. Define three small classes in the package: full-time employee, part-time employee and intern. These three kinds of employees are able to be paid, whose payroll can be calculated by the formulas:

Full-time employee: base salary + bonus

Part-time employee: working hours * payment per hour

Intern: stipend

(The full-time employee should have two data members to store base salary and bonus; the part-time employee should have two data members to store working hours and payment per hour; the intern should at least one data member to store stipend.)

3. Create the third package called test. Define a driver class (with main method) and use polymorphism to test your program.

4. Use multiple inheritance to define another class Full-time permanent employee, besides the payroll, who also has the benefit to accumulate paid time-off. A full-time permanent employee is able to accumulate 50 hours paid time-off for each year he/she has served. Then create a full-time permanent employee instance in your driver class and print out its payroll and accumulated paid time-off hours.

Hints: Create another interface with calcPaidTimeOff()method. Make the class Full-time permanent employee implements the new defined interface and payable interface. The class should have at least three data members to store the base salary, bonus, and the number of years served.

Explanation / Answer

Please find my implementation.

Question was long friend.

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//Payable.java

package hrInterface;

public interface Payable {

      void calcPayroll();

}

//PaidTimeOff.java

package hrInterface;

public interface PaidTimeOff {

      void accumulatedPaidTimeOffs();

}

//FullTimeEmployee.java

package employee;

import hrInterface.Payable;

public class FullTimeEmployee implements Payable{

      private double baseSalary;

      private double bonus;

     

     

      public FullTimeEmployee(double baseSalary, double bonus) {

            /**

            * Parameterized constructor

            */

            this.baseSalary = baseSalary;

            this.bonus = bonus;

      }

      public FullTimeEmployee() {

            /**

            * Default constructor

            */

      }

     

      public double getBaseSalary() {

            return baseSalary;

      }

      public void setBaseSalary(double baseSalary) {

            this.baseSalary = baseSalary;

      }

      public double getBonus() {

            return bonus;

      }

      public void setBonus(double bonus) {

            this.bonus = bonus;

      }

      public void calcPayroll() {

            System.out.println("Full Time Employee");

            System.out.println("Base salary: "+baseSalary);

            System.out.println("Bonus: "+bonus);

            double payroll=baseSalary+bonus;

            System.out.println("Payroll: "+payroll);

           

      }

}

//PartTimeEmployee.java

package employee;

import hrInterface.Payable;

public class PartTimeEmployee implements Payable {

      private double workingHours;

      private double paymentPerHour;

     

     

      public PartTimeEmployee(double workingHours, double paymentPerHour) {

            /**

            * Parameterized constructor

            */

            this.workingHours = workingHours;

            this.paymentPerHour = paymentPerHour;

      }

      public PartTimeEmployee() {

            /**

            * Default constructor

            */

      }

     

      public double getWorkingHours() {

            return workingHours;

      }

      public void setWorkingHours(double workingHours) {

            this.workingHours = workingHours;

      }

      public double getPaymentPerHour() {

            return paymentPerHour;

      }

      public void setPaymentPerHour(double paymentPerHour) {

            this.paymentPerHour = paymentPerHour;

      }

      public void calcPayroll() {

            System.out.println("Part Time Employee");

            System.out.println("Working hours: "+workingHours);

            System.out.println("Payment per hour: "+paymentPerHour);

            double payroll=workingHours*paymentPerHour;

            System.out.println("Payroll: "+payroll);

           

      }

     

}

//Intern.java

package employee;

import hrInterface.Payable;

public class Intern implements Payable {

      private double stipend;

      public Intern(double stipend) {

            /**

            * Parameterized constructor

            */

            this.stipend = stipend;

      }

      public Intern() {

            /**

            * Default constructor

            */

      }

      public double getStipend() {

            return stipend;

      }

      public void setStipend(double stipend) {

            this.stipend = stipend;

      }

      public void calcPayroll() {

            System.out.println("Intern");

            System.out.println("Payroll: " + stipend);

      }

}

//FullTimePermanentEmployee.java

package employee;

import hrInterface.PaidTimeOff;

public class FullTimePermanentEmployee extends FullTimeEmployee implements PaidTimeOff{

      private int yearsServed;

      public FullTimePermanentEmployee() {

            super();

            /**

            * Default constructor

            */

      }

      /**

      * As the FullTimePermanentEmployee class is extended from FullTimeEmployee class,

      * the Payable interface is implemented by default, if you want to override it,

      * you can do like following

      */

      @Override

      public void calcPayroll() {

            System.out.println("Full Time Permanent Employee");

            System.out.println("Base salary: "+getBaseSalary());

            System.out.println("Bonus: "+getBonus());

            double payroll=getBaseSalary()+getBonus();

            System.out.println("Payroll: "+payroll);

      }

      public FullTimePermanentEmployee(double baseSalary, double bonus,int yearsServed) {

            /**

            * Parameterized constructor

            */

            super(baseSalary, bonus); /*passing values to the superclass*/

            this.yearsServed=yearsServed;

      }

      public void accumulatedPaidTimeOffs() {

            System.out.println("Accumulated Time off: "+(50*yearsServed)+" hours");      

      }

}

//Driver.java

package test;

import employee.FullTimeEmployee;

import employee.FullTimePermanentEmployee;

import employee.Intern;

import employee.PartTimeEmployee;

import hrInterface.Payable;

public class Driver {

     

     

      public static void main(String[] args) {

            /**

            * creating objects of all types of employees

            */

            Payable fullTimeEmployee=new FullTimeEmployee(5000.00, 225.66);

            Payable partTimeEmployee=new PartTimeEmployee(9.15, 200.5);

            Payable intern=new Intern(2500);

           

            FullTimePermanentEmployee fullTimePermanentEmployee=newFullTimePermanentEmployee(7000, 3000, 12);

            /**

            * Displaying each employee's payrolls

            */

            fullTimeEmployee.calcPayroll();

            partTimeEmployee.calcPayroll();

            intern.calcPayroll();

            fullTimePermanentEmployee.calcPayroll();

            /**

            * Displaying the accumulated paid time off of the permanent employee

            */

            fullTimePermanentEmployee.accumulatedPaidTimeOffs();

      }

}

//OUTPUT

Full Time Employee

Base salary: 5000.0

Bonus: 225.66

Payroll: 5225.66

Part Time Employee

Working hours: 9.15

Payment per hour: 200.5

Payroll: 1834.575

Intern

Payroll: 2500.0

Full Time Permanent Employee

Base salary: 7000.0

Bonus: 3000.0

Payroll: 10000.0

Accumulated Time off: 600 hours