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

This is a c++ program Payroll System Using Inheritance and Polymorphism Define t

ID: 3761900 • Letter: T

Question

This is a c++ program

Payroll System Using Inheritance and Polymorphism

Define the following constants in a header file.

FACULTY_MONTHLY_SALARY = 5000.00

STAFF_MONTHLY_HOURS_WORKED = 160

Implement an abstract class Employee with the following requirements:

Attributes

last name (String)

first name (String)

ID number (String)

Sex - M or F

Birth date (Date)

Default argument constructor and argument constructors.

Public methods

putData that displays the following information:
ID Employee number :_________
Employee name: __________
Birth date: _______

get and set methods

pure virtual method monthlyEarning that returns the monthly earning.

3. Implement a class called Staff extending from the class Employee with the following requirements:

Attribute

Hourly rate

Default argument and argument contructors

Public methods

get and set

The method monthlyEarning returns monthly salary (hourly rate times 160)

putData that displays the following information:
ID Employee number :_________
Employee name: __________
Birth date: _______
Full Time
Monthly Salary: _________

Implelment a class Education with the following requirements:

Attributes

Degree (MS or PhD )

Major (Engineering, Chemistry, English, etc ... )

Research (number of researches)

Default argument and argument constructors.

Public methods

get and set

Implement a class Faculty extending from the class Employee with the following requirements:

Attributes

Level
"AS": assistant professor
"AO": associate professor
"FU": professor

Education object

Default argument and argument constructor

Public methods

get and set

The method monthlyEarning returns monthly salary based on the faculty's level.
AS - faculty monthly salary
AO - 1.2 times faculty monthly salary
FU - 1.4 times faculty monthly salary

putData that displays the following information:
ID Employee number :_________
Employee name: __________
Birth date: _______
XXXXX Professor where XXXXX can be Assistant, Associate or Full
Monthly Salary: _________

Implement a class called Partime extending from the class Staff with the following requirements:

Attributes

Hours worked per week

Default argument and argument constructors

Public methods

set and get

The method monthlyEarning returns monthly salary which hourly rate multiplied hours worked per week multiplied four.

putData that displays the following information:
ID Employee number :_________
Employee name: __________
Birth date: _______
Hours works per month: ______
Monthly Salary: _________

Implement a test driver program that creates a one-dimensional array of class Employee to store the objects Staff, Faculty and Partime.

Using polymorphism, display the following outputs:

a. Employee information using the method putData.

All employees

Staff

Faculty

Part-time

b. Total monthly salary for all the part-time staff .
c. Total monthly salary for all employees.

Explanation / Answer

Creating Abstract Superclass Employee

Creating Concrete Subclass SalariedEmployee

Creating Concrete Subclass HourlyEmployee

Creating Concrete Subclass CommissionEmployee

Creating Indirect Concrete Subclass BasePlusCommissionEmployee

Demonstrating Polymorphic Processing, Operator instanceof and Downcasting

Summary of the Allowed Assignments Between Superclass and Subclass Variables

final Methods and Classes

Case Study: Creating and Using Interfaces

Developing a Payable Hierarchy

Declaring Interface Payable

Creating Class Invoice

Modifying Class Employee to Implement Interface Payable

Modifying Class SalariedEmployee for Use in the Payable Hierarchy

Using Interface Payable to Process Invoices and Employees Polymorphically

Declaring Constants with Interfaces

Common Interfaces of the Java API

// Employee abstract superclass.

    public abstract class Employee

   {

       private String firstName;

       private String lastName;

     private String socialSecurityNumber;

      

     public Employee( String first, String last, String ssn )

      {

        firstName = first;

         lastName = last;

         socialSecurityNumber = ssn;

      }

      public void setFirstName( String first )

      {

         firstName = first; // should validate

      }

      public String getFirstName()

      {

         return firstName;

      }

      public void setLastName( String last )

      {

         lastName = last;

      }

      public String getLastName()

      {

         return lastName;

      }

      public void setSocialSecurityNumber( String ssn )

      {

         socialSecurityNumber = ssn;

      }

      public String getSocialSecurityNumber()

      {

         return socialSecurityNumber;

      }

     public String toString()

      {

         return String.format( "%s %s social security number: %s",

            getFirstName(), getLastName(), getSocialSecurityNumber() );

      }

     

      public abstract double earnings();

   }

SalariedEmployee concrete class extends abstract class Employee.

public class SalariedEmployee extends Employee

{

       private double weeklySalary;

       public SalariedEmployee( String first, String last, String ssn,

        double salary )

      {

        super( first, last, ssn );

        setWeeklySalary( salary );

      }

     public void setWeeklySalary( double salary )

      {

         if ( salary >= 0.0 )

           baseSalary = salary;

        else

           throw new IllegalArgumentException(

               "Weekly salary must be >= 0.0" );

      }

     

      public double getWeeklySalary()

      {

         return weeklySalary;

      }

                                                        

      public double earnings()                                            

      {

           return getWeeklySalary();                                       

     }            

      public String toString()                                    

{

      return String.format( "salaried employee: %s %s: $%,.2f",

      super.toString(), "weekly salary" , getWeeklySalary() );

      }                                    

   }

HourlyEmployee class extends Employee.

public class HourlyEmployee extends Employee

    {

       private double wage;

      private double hours;

      

      public HourlyEmployee( String first, String last, String ssn,

         double hourlyWage, double hoursWorked )

      {

         super( first, last, ssn );

         setWage( hourlyWage );

         setHours( hoursWorked );

      }

     

      public void setWage( double hourlyWage )

      {

         if ( hourlyWage >= 0.0 )

            wage = hourlyWage;

         else

            throw new IllegalArgumentException(

               "Hourly wage must be >= 0.0" );

      }

    

      public double getWage()

      {

         return wage;

      }

      public void setHours( double hoursWorked )

      {

         if ( ( hoursWorked >= 0.0 ) && ( hoursWorked <= 168.0 ) )

            hours = hoursWorked;

         else

            throw new IllegalArgumentException(

               "Hours worked must be >= 0.0 and <= 168.0" );

      }

      public double getHours()

      {

         return hours;

     }

                                                         

      public double earnings()                                           

      {                                                                 

      if ( getHours() <= 40 ) // no overtime

      return getWage() * getHours();                               

    else                                                            

      return 40 * getWage() + ( getHours() - 40 ) * getWage() * 1.5 ;

      }                                                            

      public String toString()                                              

      {                                                                    

      return String.format( "hourly employee: %s %s: $%,.2f; %s: %,.2f",

      super.toString(), "hourly wage" , getWage(),

        "hours worked", getHours() );

      }                                            

   }

CommissionEmployee class extends Employee.

public class CommissionEmployee extends Employee

    {

       private double grossSales;

       private double commissionRate;

      public CommissionEmployee( String first, String last, String ssn,

         double sales, double rate )

      {

         super( first, last, ssn );

         setGrossSales( sales );

         setCommissionRate( rate );

      }

      public void setCommissionRate( double rate )

      {

         if ( rate > 0.0 && rate < 1.0 )

            commissionRate = rate;

         else

            throw new IllegalArgumentException(

               "Commission rate must be > 0.0 and < 1.0" );

      }

      public double getCommissionRate()

      {

         return commissionRate;

      }

      public void setGrossSales( double sales )

      {

         if ( sales >= 0.0 )

            grossSales = sales;

         else

            throw new IllegalArgumentException(

               "Gross sales must be >= 0.0" );

      }

      public double getGrossSales()

      {

         return grossSales;

      }                                                          

      public double earnings()                                           

     {                                                                  

      return getCommissionRate() * getGrossSales();                   

      }                                                 

      public String toString()                                   

      {                                   

      return String.format( "%s: %s %s: $%,.2f; %s: %.2f",

            "commission employee", super.toString(),              

            "gross sales", getGrossSales(),                      

            "commission rate", getCommissionRate() );            

      }                                   

}

BasePlusCommissionEmployee class extends CommissionEmployee.

public class BasePlusCommissionEmployee extends CommissionEmployee

    {

       private double baseSalary;

       public BasePlusCommissionEmployee( String first, String last,

         String ssn, double sales, double rate, double salary )

      {

         super( first, last, ssn, sales, rate );

         setBaseSalary( salary );

      }

      public void setBaseSalary( double salary )

      {

         if ( salary >= 0.0 )

            baseSalary = salary;

         else

            throw new IllegalArgumentException(

               "Base salary must be >= 0.0" );

      }

      public double getBaseSalary()

      {

         return baseSalary;

      }                                                       

      public double earnings()                                            

      {                                                                   

      return getBaseSalary() + super.earnings();                       

      }                                                       

      public String toString()                                           

      {                                                                  

      return String.format( "%s %s; %s: $%,.2f",

            "base-salaried", super.toString(),                           

            "base salary", getBaseSalary() );                            

      }                                           

}

Employee hierarchy test program.

public class PayrollSystemTest

    {

      public static void main( String[] args )

       {

                                                   

          SalariedEmployee salariedEmployee =                                

         new SalariedEmployee( "John", "Smith" , "111-11-1111", 800.00 );

         HourlyEmployee hourlyEmployee =                                    

         new HourlyEmployee( "Karen", "Price" , "222-22-2222", 16.75, 40 );

         CommissionEmployee commissionEmployee =                            

         new CommissionEmployee(                                         

         "Sue", "Jones", "333-33-3333", 10000, .06 );

         BasePlusCommissionEmployee basePlusCommissionEmployee =            

         new BasePlusCommissionEmployee(                                  

            "Bob", "Lewis", "444-44-4444", 5000, .04, 300 );                

         System.out.println( "Employees processed individually: " );

         System.out.printf( "%s %s: $%,.2f ",

            salariedEmployee, "earned", salariedEmployee.earnings() );

         System.out.printf( "%s %s: $%,.2f ",

            hourlyEmployee, "earned", hourlyEmployee.earnings() );

         System.out.printf( "%s %s: $%,.2f ",

            commissionEmployee, "earned", commissionEmployee.earnings() );

         System.out.printf( "%s %s: $%,.2f ",

            basePlusCommissionEmployee,

            "earned", basePlusCommissionEmployee.earnings() );

        

         Employee[] employees = new Employee[ 4 ];

        

         employees[ 0 ] = salariedEmployee;         

         employees[ 1 ] = hourlyEmployee;           

         employees[ 2 ] = commissionEmployee;       

         employees[ 3 ] = basePlusCommissionEmployee;

         System.out.println( "Employees processed polymorphically: " );

        

         for ( Employee currentEmployee : employees )

         {

            System.out.println( currentEmployee ); // invokes toString

           

            if ( currentEmployee instanceof BasePlusCommissionEmployee )

            {

              

               BasePlusCommissionEmployee employee =

                  ( BasePlusCommissionEmployee ) currentEmployee;

               employee.setBaseSalary( 1.10 * employee.getBaseSalary() );

               System.out.printf(

                  "new base salary with 10%% increase is: $%,.2f ",

                  employee.getBaseSalary() );

            }

            System.out.printf(

               "earned $%,.2f ", currentEmployee.earnings() );

         }

        

         for ( int j = 0; j < employees.length; j++ )     

            System.out.printf( "Employee %d is a %s ", j,

               employees[ j ].getClass().getName() );     

      }

}

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