Let\'s see if we can build up the * pseudocode * for these classes together to s
ID: 3898579 • Letter: L
Question
Let's see if we can build up the *pseudocode* for these classes together to some extent. We'll start off with the following stubs (outlines) of the four classes. Can we extend them to include some of the required elements from the problem specification?
Please note: pseudocode, and the outline stub below, are just tools to help make development of the solution easier. Most people find these tools helpful but, if they don't seem helpful for you right now, it's perfectly okay to not utilize them. As the programs you develop become more complex, though, you'll probably need intermediate steps or approaches to make getting a handle on the solution more tractable.
Please remember: *what's below is a stub, not pseudocode*; this stub is an outline of what your program will look like, not details of the instructions, which is what the pseudocode will provide.
Please note: in the following discussion, please do *NOT* post any actual Java code and only add pseudocode!
// Base Class Declaration
public class Employee { // Declare the three fields
// Declare the constructor
// Declare your accessors and mutators
// Declare your getWeeklyPay() method: Standard pay = hours worked * rate for up to 40 hours - no overtime
}
// Declare first sub-class called UnionEmployee
public class ... { // Declare the field
// Declare the explicit-value constructor
// Declare the mutator
// Overload the base class' getWeeklyPay() method
}
// Declare second sub-class called CommissionEmployee
public class ... { // Declare the two fields
// Declare the explicit-value constructor
// Declare the mutators
// Overload the base class' getWeeklyPay() method
}
// Declare the test driver class:
public class TestDriverClass {
// Declare the helper display() method which accepts an Employee object reference and int hours
// Declare the main() method: public static void main(String args[]) {
// Declare a UnionEmployee object
// Declare a CommissionEmployee object
// Display their calculations for various cases
}
}
Note: Plagiarism is checked
Explanation / Answer
// Base Class Declaration
class Employee { // Declare the three fields
private int id;
private int hoursWorked;
private double rate;
// Declare the constructor
public Employee(int id,int hoursWorked,double rate)
{
this.id = id;
this.hoursWorked = hoursWorked;
this.rate = rate;
}
// Declare your accessors and mutators
public void setID(int id)
{
this.id = id;
}
public int getID()
{
return id;
}
public void setHoursWorked(int hoursWorked)
{
this.id = id;
}
public int getHoursWorked()
{
return hoursWorked;
}
public void setRate(double rate)
{
this.rate = rate;
}
public double getRate()
{
return rate;
}
// Declare your getWeeklyPay() method: Standard pay = hours worked * rate for up to 40 hours - no overtime
public double getWeeklyPay()
{
return hoursWorked * rate;
}
}
// Declare first sub-class called UnionEmployee
class UnionEmployee extends Employee
{ // Declare the field
private double incentive;
// Declare the explicit-value constructor
public UnionEmployee(int id,int hoursWorked,double rate,double incentive)
{
super(id,hoursWorked,rate);// call to base class constructor
this.incentive = incentive;
}
// Declare the mutator
public double getIncentive()
{
return incentive;
}
// Overload the base class' getWeeklyPay() method
public double getWeeklyPay()
{
return super.getWeeklyPay()+incentive;
}
}
// Declare second sub-class called CommissionEmployee
class CommissionEmployee extends Employee
{ // Declare the two fields
private double commission;
private int sales;
// Declare the explicit-value constructor
public CommissionEmployee(int id,int hoursWorked,double rate,double commission,int sales)
{
super(id,hoursWorked,rate);
this.commission = commission;
this.sales = sales;
}
// Declare the mutators
public double getCommission()
{
return commission;
}
public int getSales()
{
return sales;
}
// Overload the base class' getWeeklyPay() method
public double getWeeklyPay()
{
return super.getWeeklyPay() + commission*sales;
}
}
// Declare the test driver class:
class TestDriverClass {
// Declare the helper display() method which accepts an Employee object reference and int hours
public static void display(Employee e,int hours)
{
System.out.println("Number of hours employee worked : "+hours);
}
// Declare the main() method:
public static void main(String args[]) {
// Declare a UnionEmployee object
UnionEmployee ue = new UnionEmployee(1224,45,6.7,400.50);
// Declare a CommissionEmployee object
CommissionEmployee ce = new CommissionEmployee(1445,50,5.8,0.05,3400);
// Display their calculations for various cases
display(ue,45);
System.out.println("WeeklyPay of Union Employee : $"+ue.getWeeklyPay());
display(ce,50);
System.out.println("WeeklyPay of Commission Employee : $"+ce.getWeeklyPay());
}
}
Output:
Number of hours employee worked : 45
WeeklyPay of Union Employee : $702.0
Number of hours employee worked : 50
WeeklyPay of Commission Employee : $460.0
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.