Question
This is my employee class: package chegg1; import java.text.DecimalFormat; import java.util.Comparator; public class Employee implements Comparable { public String employeeNumber; public String name; public String
This is my employee class:
package chegg1;
import java.text.DecimalFormat;
import java.util.Comparator;
public class Employee implements Comparable
public String employeeNumber;
public String name;
public String department;
public Double salary;
// no arg const
public Employee() {
this.employeeNumber = null;
this.name = null;
this.department = null;
this.salary = 0.0;
}
public Employee(String employeeNumber, String name, String department,
Double salary) {
this.employeeNumber = employeeNumber;
this.name = name;
this.department = department;
this.salary = salary;
}
public String getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(String employeeNumber) {
this.employeeNumber = employeeNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
@Override
public String toString() {
DecimalFormat numFormat = new DecimalFormat("######.##");
String salaryS = numFormat.format(salary);
System.out
.printf("employeeNumber: %.6s, name: %.25s, department: %.8s, salary: %.6f",
employeeNumber, name, department, salary);
return "employeeNumber=" + employeeNumber + ", name=" + name
+ ", department=" + department + ", salary="
+ Double.valueOf(salary) + "]";
}
public boolean equals(Employee emp) {
if (this == emp)
return true;
if (emp == null)
return false;
if (getClass() != emp.getClass())
return false;
Employee other = (Employee) emp;
if (employeeNumber == null) {
if (other.employeeNumber != null)
return false;
} else if (!employeeNumber.equals(other.employeeNumber))
return false;
return true;
}
@Override
public int compareTo(Employee o) {
// TODO Auto-generated method stub
if(Integer.valueOf(this.employeeNumber) < Integer.valueOf(o.employeeNumber)){
return -1;
}else if(Integer.valueOf(this.employeeNumber) < Integer.valueOf(o.employeeNumber)){
return 1;
}else{
return 0;
}
}
}
Please use JAVA
Create a class to implement an ordered linked list of employees (increasing order of employee number), the HumanResources class.
Inside the HumanResources class you, create a private class to define a node object. It will have two private data members, one member for an employee object and one for the address on the next node (i.e. the link). You may define one or more constructor for the node class.
The HumanResources class will have one private data member:
first which will be an object of the node class. It will store the reference (address) of the first node in the list.
The HumanResources class will include the following instance methods:
public HumanResources() Zero-parameter constructor to initialize an empty list.
public HumanResources(HumanResources) Copy constructor to create a new object (linked list) identical in content to the given parameter.
public boolean isEmpty() Method that returns true if the list is empty and false otherwise.
public boolean addEmployee(Employee) Method that inserts a new employee in the list (in increasing order of employee number). It returns true if the employee was added to the list. It returns false if the employee is already in the list (same employee number).
public boolean deleteEmployee(String) Method to delete the employee with the given employee number from the list. It returns true if the employee was deleted. It returns false if the employee was not in the list.
public Employee findEmployee(String) Method that returns an employee object if the employee with the given number is found in the list. It returns null otherwise.
public boolean changeDepartment(String, String) For the given employee (first parameter), this method changes the department value to the given department (second parameter). It returns true if the department was successfully changed (employee was present in the list); it returns false otherwise.
public boolean adjustSalary (String, double ) For the given employee (first parameter), this method adjuststhe salary value by adding the given amount (second parameter) to the existing salary; the amount given may be positive or negative. It returns true if the employee salary was adjusted; it returns false otherwise.
public String toString() Method that returns the content of the list, i.e. all the data for each employee on a separate line.
public String decreasingOrder() Method that returns the content of the list, i.e. all the data for each employee on a separate line but in decreasing order of employee number. The method should call a recursive method (private) to achieve this.
Important Notes:
You must code private method(s) to handle everything relating to the searching in the list to obtain the reference to the given node and the one before it.
The addEmployee, deleteEmployee and findEmployee method must use the private method(s) mentioned above in i). There should not be a loop in those three methods nor in the changeDepartment oradjustSalary methods.
You must code a private recursive method to set up the string with the employee data in decreasing order.
For efficiency reasons, the copy constructor should not call the addEmployee method to create the copy.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started