The objective of this programming assignment is to experience the use of inherit
ID: 1812961 • Letter: T
Question
The objective of this programming assignment is to experience the use of inheritance in Java and to see how polymorphism works with inheritance in Java.
The assignment involves writing three classes, plus a test class. The base class is an employee class which contains a couple of attributes common to all employees and a fundamental method to calculate pay. The two derived classes are a commissioned employee that adds payment of a sales commission as part of the pay calculation, and a union employee which adds overtime payment and union dues as part of the pay calculation. The test program will be structured to include a method which accepts a base class reference and demonstrates polymorphic behavior
1. 1. An Employee contains a name, a department where the employee works, and an hourly rate of pay. An explicit value constructor should be provided to set all three values when an Employee object is created. There should be mutator methods to set the values of the department and the pay rate. There should be one accessor method which returns a string containing the name and the department in which the employee works. Finally, there should be a weekly pay method that takes an integer parameter for the number of hours worked and returns the weekly pay. If the number of hours worked is less than 40 hours, the pay is the number of hours times the rate. If the number of hours worked is 40 or more, the pay is 40 times the rate.
Explanation / Answer
package pkg; public class Employee { public static String name1; public static String department; public static double hoursWorked; public static double payRate; public Employee(String name1, double hoursWorked, double payRate, String department) { super(); Employee.name1 = name1; Employee.department = department; Employee.hoursWorked = hoursWorked; Employee.payRate = payRate; // Calculations Begin Object product = payRate * hoursWorked; //Display Results System.out.println(name1);//print first name System.out.printf("total income this week is $%.2f ", product); } public Employee(String name12, double payRate2, double hoursWorked2, String department2, double uniondues) { } public String getName1() { return name1; } public void setName1(String name1) { Employee.name1 = name1; } public String getDepartment(){ return department; } public void setDepartment(String department){ Employee.department =department; } public double getHoursWorked() { return hoursWorked; } public void setHoursWorked(double hoursWorked) { Employee.hoursWorked = hoursWorked; } public double getPayRate() { return payRate; } public void setPayRate(double payRate) { Employee.payRate = payRate; } public void disp() { System.out.printf("Name=%d Payrate= %7.2d Department=%d", name1, payRate, department);} } ]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.