Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For the subpublic class Employee of the base public class Person example provided in the tutorial, what if you need to keep track of the

For the subpublic class Employee of the base public class Person example provided in the tutorial, what if you need to keep track of the department for each employee.
What code segment could be used to properly initialize, and add methods to set and get this value?
a.)
public class Employee extends Person {
private int employeeId;
private double salary;
private String department;
public Employee(String firstName,String lastName,String jobTitle,double sal,int empId,String department){
super(firstName,lastName,jobTitle);
this.employeeId = empId;
this.salary = sal;
this.vacationDaysPerYear =14;
this.vacationDays = this.vacationDaysPerYear;
this.department = department;
}
public void getDepartment(department){
return "Department: "+ department;
}
public String setDepartment(){
this.department = department;
}
}
b.)
public class Employee extends Person {
private int employeeId;
private double salary;
private String department;
public Employee(String firstName,String lastName,String jobTitle,double sal,int empId,String department){
super(firstName,lastName,jobTitle, department);
this.employeeId = empId;
this.salary = sal;
this.vacationDaysPerYear =14;
this.vacationDays = this.vacationDaysPerYear;
}
public String getDepartment(){
return "Department: "+ department;
}
public void setDepartment(String department){
this.department = department;
}
}
c.)
public class Employee extends Person {
private int employeeId;
private double salary;
private String department;
public Employee(String firstName,String lastName,String jobTitle,double sal,int empId,String department){
super(firstName,lastName,jobTitle);
this.employeeId = empId;
this.salary = sal;
this.vacationDaysPerYear =14;
this.vacationDays = this.vacationDaysPerYear;
this.department = department;
}
public String getDepartment(){
return "Department: "+ department;
}
public void setDepartment(String department){
this.department = department;
}
}
d.)
public class Employee extends Person {
private int employeeId;
private double salary;
private String department;
public Employee(String firstName,String lastName,String jobTitle,double sal,int empId,String department){
super(firstName,lastName,jobTitle);
this.employeeId = empId;
this.salary = sal;
this.vacationDaysPerYear =14;
this.vacationDays = this.vacationDaysPerYear;
emp_department = department;
}
public String getDepartment(){
return "Department: "+ department;
}
public void setDepartment(String department){
emp_department = department;
}
}

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

Recommended Textbook for

More Books

Students also viewed these Databases questions