Java: Inheritance Programming Employee, CommissionEmployee, HourlyEmployee and SalaryEmployee

  1. Home
  2. Homework Library
  3. Computer Science
  4. Java Programming
  5. Java: Inheritance Programming Employee, CommissionEmployee, HourlyEmployee and SalaryEmployee


Program Description:
This project will have you create a simple class hierarchy building upon the Employee example discussed in class.
A total of five classes are required.
Employee – A class which the other employee types inherit from
HourlyEmployee – An employee whose pay is based upon an hourly wage and hours worked
SalaryEmployee – An employee whose pay is based upon a yearly salary
CommissionEmployee – An employee whose pay is based upon a commission rate and sales amount
EmployeeTest – Contains main method. Creates one of each sub type of Employee and performs actions upon them.

Content of

public class EmployeeTest
   public static void main(String args[])
      //Create references for our objects
      HourlyEmployee hourly;
      SalaryEmployee salary;
      CommissionEmployee commission;

      //The sum of all bonuses will be placed here
      double bonusPayout = 0;

      //Create and print a new HourlyEmployee
      hourly = HourlyFactory();
      System.out.printf("\n%s\n", hourly);
      //Create and print a new SalaryEmployee
      salary = SalaryFactory();      
      System.out.printf("\n%s\n", salary);
      //Create and print a new CommissionEmployee
      commission = CommissionFactory();
      System.out.printf("\n%s\n", commission);

      //Alter some values of Hourly and Commission
      System.out.println("Increasing Hourly's hours worked by 50.");

      System.out.println("Increasing Commissions's sales by 150,000.\n");

      //Output weekly pay for each Employee
      System.out.printf("Hourly Payout: %.2f\n", hourly.calculateWeeklyPay());
      System.out.printf("Salary Payout: %.2f\n", salary.calculateWeeklyPay());
      System.out.printf("Commission Payout: %.2f\n\n", commission.calculateWeeklyPay());

      //Find total bonus payout
      System.out.println("Finding total bonus payout...");
      bonusPayout += hourly.holidayBonus();
      bonusPayout += salary.holidayBonus();
      bonusPayout += commission.holidayBonus();

      System.out.printf("Bonus Payout is %.2f\n\n", bonusPayout);

      //Reset the week and apply raises to all Employees
      System.out.println("Applying annual raises and resetting week...");

      //Output Employees after changes
      System.out.printf("%s\n%s\n%s\n", hourly, salary, commission);

   //Retrieve input and create HourlyEmployee
   public static HourlyEmployee HourlyFactory()
      System.out.println("Creating HourlyEmployee...");
      return new HourlyEmployee("Steve", "Rogers", 'A', 'M', 12345, true, 15.34);
   //Retrieve input and create SalaryEmployee
   public static SalaryEmployee SalaryFactory()
      System.out.println("Creating SalaryEmployee...");
      return new SalaryEmployee("Kitty", "Pryde", 'X', 'F', 54321, true, 75000);
   //Retrieve input and create CommissionEmployee
   public static CommissionEmployee CommissionFactory()
      System.out.println("Creating CommissionEmployee...");
      return new CommissionEmployee("Johnny", "Storm", 'F', 'L', 976499, false, 2.5);

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.text.DecimalFormat;

* @author
public class HourlyEmployee extends Employee{
    /// atrributes
    private double wage;
    private double hoursWorked;

    * constructor
    * @param firstName
    * @param lastName
    * @param middleInitial
    * @param gender
    * @param employeeNum
    * @param fulltime
    * @param wage
    public HourlyEmployee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double wage) {
       super(firstName, lastName, middleInitial, gender, employeeNum, fulltime);
       this.wage = wage;
       this.hoursWorked = 0.0;
    * Requesting to increase by a negative value should give no change, and report an error to the user.
    * @param hours
    public void increaseHours(double hours){
       if (hours < 0.0) {
            System.out.println("It's unable to increase by a negative value");
       } else {
            hoursWorked += hours;

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats