I seem to be getting the constructor Employee in class Employee cannot be applied to given types; error and I'm not sure how to fix it. Im fairly new to coding so the simpler explanation the better. method where the error occurs specifically the "new Employee();" in the first line
Collections.sort(employees, new Employee());
System.out.println("\nFirst and Last Names of Employees sorted based on first Name\n");
for (Employee employee : employees) {
System.out.println("First Name: " + employee.getfirstName() + " Last Name: " + employee.getlastName()
+ " Salary: " + employee.getSalary());
}
List<Employee> newHirees = readFile(hirefile);
// Add new Hired employees
employees.addAll(newHirees);
Collections.sort(employees, new Employee());
System.out.println("\nFirst and Last Names of Employees sorted based on first Name after adding new hires\n");
for (Employee employee : employees) {
System.out.println("First Name: " + employee.getFirstName() + " Last Name: " + employee.getLastName()
+ " Salary: " + employee.getSalaryPaid());
}
List<Employee> firedEmployees = readFile(firefile);
System.out.println("\nFirst and Last Names of Employees After removing fired employees\n");
for (Employee fired : firedEmployees) {
String firstName=fired.getFirstName();
String lastname=fired.getLastName();
for (Employee employee : employees) {
if (employee.getFirstName().trim().equals(firstName)
&& employee.getLastName().equals(lastname)) {
employees.remove(employee);
}
}
}
for (Employee employee : employees) {
System.out.println("First Name: " + employee.getFirstName() + " Last Name: " + employee.getLastName());
}
}
//Employee class
public class Employee{
String firstName;
String lastName;
String gender;
int tenure;
String rate;
double salary;
public Employee( String firstName, String lastName,String gender,int tenure, String rate,double salary )
{
this.firstName=firstName;
this.lastName=lastName;
this.gender=gender;
this.tenure=tenure;
this.rate=rate;
this.salary=salary;
}
//get and set methods
public void setfirstName(String nm) {
this.firstName=nm;}
public void setlastName(String nm) {
this.lastName=nm;}
String getfirstName() {
return this.firstName;}
String getlastName() {
return this.lastName;}
public void setGender(String nm) {
this.gender=nm;}
public void setRate(String nm) {
this.rate=nm;}
String getGender(){
return this.gender;}
String getRate(){
return this.rate;}
void setSalary(double pr){
this.salary=pr;}
double getSalary(){
return this.salary;}
void setTenure(int q){
this.tenure=q;}
int getTenure(){
return this.tenure;}
public String toString(){
String s=this.firstName+" "+this.lastName+" "+this.gender+" "+this.tenure+" "+
this.rate+" "+this.salary;
return(s);
}
}
You don't have a parameterless constructor, so new Employee()
won't work.
Why are you trying to pass that as a parameter there anyway?