Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will work with 3 classes in this lab. Employee.java (completed) HourlyEmployee.java HumanResource.java (completed) Employee is the superclass, and HourlyEmployee is a subclass of Employee

You will work with 3 classes in this lab.

Employee.java (completed)

HourlyEmployee.java

HumanResource.java (completed)

Employee is the superclass, and HourlyEmployee is a subclass of Employee class. Complete the definition of HourlyEmployee class following the instructions.

HourlyEmployee.java

/*FIXME(1) Make HourlyEmployee a subclass of Employee*/ public class HourlyEmployee extends Employee { private double hourlyRate; /*FIXME(2) Complete the default constructor to set hourlyRate to 0.0*/ public HourlyEmployee() { } /*FIXME(3) Complete the argumented constructor to set each field properly Note that you can call the superclass constructor to initialize the fields defined in the superclass The second video in Canvas shows an example on this.*/ public HourlyEmployee(String name, String department, String id, double rate) { } /*FIXME(4) Complete the definition of the accessor for hourlyRate*/ public double getHourlyRate() { } /*FIXME(5) Complete the definition of the mutator for hourlyRate*/ public void setHourlyRate(double rate) { } /*FIXME(6) Complete the definition of the toString method, which will return a String includes name, department, id, and hourlyRate of the employee Note that you can call the overriden toString() method defined in the superclass and append the information about the hourlyRate Example: Name: John Smith, Department: Sales, ID: jsmith1, Hourly Rate: $18.2*/ @Override public String toString() { }

Employee.java

public class Employee { private String name; private String department; private String id; // Default constructor. Set protected variables to the empty string or 0 public Employee() { name = ""; department = ""; id = ""; } // Constructor with parameters to set the private variables public Employee(String name, String department, String id) { this.name = name; this.department = department; this.id = id; } public String getName() { return name; } public String getDepartment() { return department; } public String getId() { return id; } public void setDepartment(String department) { this.department = department; } public String toString() { return "Name: " + name + ", Department: " + department + ", ID: " + id; } }

HumanResource.java

public class HumanResource { public static void main(String[] args) { HourlyEmployee employee1 = new HourlyEmployee("John Smith", "Sales", "jsmith1", 18.2); HourlyEmployee employee2 = new HourlyEmployee("Amy Brown", "Marketing", "abrown3", 22.5); HourlyEmployee employee3 = new HourlyEmployee(); System.out.println(employee1); System.out.println(employee2); System.out.println(employee3); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions