Java 使用file类并将其与max heap方法结合使用?
我有一个课堂作业,我必须创建这样一个文件:Java 使用file类并将其与max heap方法结合使用?,java,Java,我有一个课堂作业,我必须创建这样一个文件: 098765 Henry M. Anthony 32000.00 Accounting Manager 15 但还有5名其他员工。 我需要使用max-heap方法对其进行排序。我创建了一个employee类。程序应该对方法进行排序,并将其显示在新文件中 public Employee(String id, String name, double salary, String department, String position, int years
098765
Henry M. Anthony
32000.00
Accounting
Manager
15
但还有5名其他员工。
我需要使用max-heap方法对其进行排序。我创建了一个employee类。程序应该对方法进行排序,并将其显示在新文件中
public Employee(String id, String name, double salary, String department, String position, int years)
{
this.id = id;
this.name = name;
this.salary = salary;
this.department = department;
this.position = position;
this.years = years;
}
public void setID(String id){
this.id = id;
}
public String getID(){
return id;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setSalary(double salary){
this.salary = salary;
}
public double getSalary(){
return salary;
}
public void setDepartment(String department){
this.department = department;
}
public String getDepartment(){
return department;
}
public void setPosition(String position){
this.position = position;
}
public String getPosition(){
return position;
}
public void setYears(int years){
this.years = years;
}
public int getYears(){
return years;
}
public String toString()
{
return "Identification " + this.id + "\nName: " + this.name + "\nSalary: "
+ this.salary + "\nDepartment: " + department + "\nPosition: "
+ position + "\nYears of Service: " + years;
}
有人能告诉我如何使用文件中的信息并将其分配给我的employee类吗?还是我做得不对?您(正确地)创建了一个POJO(普通旧Java对象),它可以封装单个employee。你打算如何读取员工数据?我正在尝试按薪水排序排序排序可能是第二步(或第三步)。首先,您需要一种加载数据的方法,但您没有提供有关这方面的信息。