我似乎得到类Employee中的构造函数Employee不能应用于给定的类型;错误,我不知道如何解决它。我是一个相当新的编码,所以更简单的解释越好。 发生错误的方法 特别是“新员工();”在第一行
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);
}
}
答案 0 :(得分:0)
您没有无参数构造函数,因此new Employee()
无法正常工作。
为什么你试图将其作为参数传递给那里?