Question

Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its...

Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its variables (firstName and lastName). It should contain an abstract method called payPrint. Below is the source code for the Employee9C superclass:

public class Employee9C {
  
//declaring instance variables
private String firstName;
private String lastName;
//declaring & initializing static int variable to keep running total of the number of paychecks calculated
static int counter = 0;
  
//constructor to set instance variables
public Employee9C(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
  
//toString method that prints out the results
public String toString() {
return ("The employee's full name is " + firstName + " " + lastName + ".");
}
}

The three subclasses (hourly, salaried, and commission employee) should inherit the abstract class and use its constructor to instantiate an object and set those instance variables mentioned before (firstName and lastName). To make things easy, the implementation of payPrint can use the toString method. Below are the source code for the subclasses.

public class HourlyEmployee9C extends Employee9C {
  
//declaring instance variables
private int hrsWorked;
private double hrlyRate, regularPay, otPay, wklyPaycheck;
  
//constructor to set instance variables
public HourlyEmployee9C(String firstName, String lastName, int hrsWorked,
double hrlyRate, double regularPay, double otPay) {
  
//calling super class constructor
super (firstName, lastName);
  
this.hrsWorked = hrsWorked;
this.hrlyRate = hrlyRate;
this.regularPay = regularPay;
this.otPay = otPay;
counter++;
}
  
//method that calculates the weekly paycheck
public void WklyPaycheck() {
wklyPaycheck = regularPay + otPay;
}
  
//getter(method) that retrieves the "wklyPaycheck"
public double getWklyPaycheck() {
return wklyPaycheck;
}
  
//toString method that prints out the results and overrides the "Employee9C" toString method
@Override
public String toString() {
return (super.toString() + " The employee is a Hourly Employee and its "
+ "weekly paycheck amount is $" + wklyPaycheck + ".");
}
}

public class SalariedEmployee9C extends Employee9C {
  
//declaring instance variables
private double yrlySalary;
private double bonusPercent;
private double wklyPay;   
//constant variable representing the number of weeks in a year
private final static double weeks = 52;
  
//constructor to set instance variables
public SalariedEmployee9C(String firstName, String lastName, double yrlySalary,
double bonusPercent) {
  
//calling super class constructor
super(firstName, lastName);
  
this.yrlySalary = yrlySalary;
this.bonusPercent = bonusPercent;  
counter++;
}
  
//method that calculates the weekly pay
public void WeeklyPay() {
wklyPay = (yrlySalary * (1.0 + bonusPercent/100.0)) / weeks;
}
  
//toString method that prints out the results and overrides the "Employee9C" toString method
public String toString() {
return super.toString() + " The employee is a Salaried Employee and its "
+ "weekly paycheck amount is $" + Math.round(wklyPay) + ".";
}
}

public class CommissionEmployee9C extends Employee9C {
  
//declaring instance variables
private int soldItems;
private double itemCost, wklyPay;
//constant variable representing the base pay for the commission employee
private static final double baseComm = 200;
  
//constructor to set instance variables
public CommissionEmployee9C(String firstName, String lastName, int soldItems,
double itemCost) {
  
//calling super class constructor
super(firstName, lastName);
  
this.soldItems = soldItems;
this.itemCost = itemCost;
counter++;
}
  
//method that calculates the weekly pay
public void WeeklyPay() {
wklyPay = baseComm + ((10.0/100.0) * (double)soldItems * itemCost);
}
  
//toString method that prints out the results and overrides the "Employee9C" toString method
public String toString() {
return super.toString() + " The employee is a Commission Employee and its "
+ "weekly paycheck amount is $" + wklyPay + ".";
}
}

Homework Answers

Answer #1

Here is the solution for the above assignment.

Code :

File name : Employee9C.java

abstract public class Employee9C {

  

    //declaring instance variables

    private String firstName;

    private String lastName;

    //declaring & initializing static int variable to keep running total of the number of paychecks calculated

    static int counter = 0;

      

    //constructor to set instance variables

    public Employee9C(String firstName, String lastName) {

    this.firstName = firstName;

    this.lastName = lastName;

    }

      

    //toString method that prints out the results

    public String toString() {

    return ("The employee's full name is " + firstName + " " + lastName + ".");

    }

    abstract void payPrint();

}

Filename: CommissionEmployee9C.java

Code :

public class CommissionEmployee9C extends Employee9C {

      

    //declaring instance variables

    private int soldItems;

    private double itemCost, wklyPay;

    //constant variable representing the base pay for the commission employee

    private static final double baseComm = 200;

      

    //constructor to set instance variables

    public CommissionEmployee9C(String firstName, String lastName, int soldItems,

    double itemCost) {

      

    //calling super class constructor

    super(firstName, lastName);

      

    this.soldItems = soldItems;

    this.itemCost = itemCost;

    counter++;

    }

      

    //method that calculates the weekly pay

    public void WeeklyPay() {

        wklyPay = baseComm + ((10.0/100.0) * (double)soldItems * itemCost);

    }

      

    //toString method that prints out the results and overrides the "Employee9C" toString method

    public String toString() {

    return super.toString() + " The employee is a Commission Employee and its "

    + "weekly paycheck amount is $" + wklyPay + ".";

    }

    public void payPrint() {

        WeeklyPay();

        System.out.println(toString());

    }

    }

Filename : SalariedEmployee9C.java

Code:

public class SalariedEmployee9C extends Employee9C {

      

    //declaring instance variables

    private double yrlySalary;

    private double bonusPercent;

    private double wklyPay;   

    //constant variable representing the number of weeks in a year

    private final static double weeks = 52;

      

    //constructor to set instance variables

    public SalariedEmployee9C(String firstName, String lastName, double yrlySalary,

    double bonusPercent) {

      

    //calling super class constructor

    super(firstName, lastName);

      

    this.yrlySalary = yrlySalary;

    this.bonusPercent = bonusPercent;  

    counter++;

    }

      

    //method that calculates the weekly pay

    public void WeeklyPay() {

    wklyPay = (yrlySalary * (1.0 + bonusPercent/100.0)) / weeks;

    }

      

    //toString method that prints out the results and overrides the "Employee9C" toString method

    public String toString() {

    return super.toString() + " The employee is a Salaried Employee and its "

    + "weekly paycheck amount is $" + Math.round(wklyPay) + ".";

    }

    public void payPrint() {

        WeeklyPay();

        System.out.println(toString());

    }

    }

Also I created a driver class which tests the functionlaity of the program.

Additionally, I have added comments in the driver class for your better understanding.

Filename: DriverClass.java

Code:

public class DriverClass {

    public static void main(String[] args) {

        // Here observe that reference type is Employee9C and it is refereing to object of type CommissionEmployee9C

        Employee9C commEmp = new CommissionEmployee9C("Mark", "Henry", 10, 30);

        commEmp.payPrint();

        // Here observe that reference type is Employee9C and it is refereing to object of type SalariedEmployee9C

        Employee9C salariedEmp = new SalariedEmployee9C("Issac", "Newton", 500000, 10);

        salariedEmp.payPrint();

        // Here observe that reference type is Employee9C and it is refereing to object of type HourlyEmployee9C

        Employee9C hourlyEmp = new HourlyEmployee9C("Alan", "Turing", 12, 10, 5, 4);

        hourlyEmp.payPrint();

        

    }

}

Output Screenshot

Thank You!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named Cat (assuming in Cat.java file).   The Animal class has the following protected instance variables: boolean vegetarian, String eatings, int numOfLegs and the following public instance methods: constructor without parameters: initialize all of the instance variables to some default values constructor with parameters: initialize all of the instance variables to the arguments SetAnimal: assign arguments to all...
Class VacationPackage java.lang.Object triptypes.VacationPackage Constructor Summary Constructors Constructor and Description VacationPackage(java.lang.String name, int numDays) Initializes a...
Class VacationPackage java.lang.Object triptypes.VacationPackage Constructor Summary Constructors Constructor and Description VacationPackage(java.lang.String name, int numDays) Initializes a VacationPackage with provided values. Method Summary All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description boolean equals(java.lang.Object other) Provides a logical equality comparison for VacationPackages and any other object type. double getAmountDue() This method provides the remaining amount due to the travel agent for this trip less any deposit made upfront. abstract double getDepositAmount() This method provides the required...
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and...
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor...
public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor public Bicycle( String name, int license ) { ownerName = name;    licenseNumber = license; } // Returns the name of the bicycle's owner public String getOwnerName( ) { return ownerName; } // Assigns the name of the bicycle's owner public void setOwnerName( String name ) { ownerName = name; } // Returns the license number of the bicycle public int getLicenseNumber( ) {...
Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a...
Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a class named Triangle that extends GeometricObject. The class contains: Three double fields named side1, side2, and side3 with default values = 1.0. These denote the three sides of the triangle A no-arg constructor that creates a default triangle A constructor that creates a triangle with parameters specified for side1, side2, and side3. An accessor method for each side. (No mutator methods for the sides)...
Consider the following code snippet: Employee programmer = new Employee(10254, "exempt"); String str = programmer.toString(); Assume...
Consider the following code snippet: Employee programmer = new Employee(10254, "exempt"); String str = programmer.toString(); Assume that the Employee class has not implemented its own toString() method. What value will the variable str contain when this code is executed? Group of answer choices the variable will become a null reference the code will not compile because Employee has not implemented toString() the default from Object, which is the class name of the object and its hash code the string representations...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also define...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT