class EmpManager{
private ArrayList Emp = null;
public EmpManager(){
Emp = new ArrayList();
}
//添加雇员
public void addEmp(Employee employee){
Emp.add(employee);
}
//根据编号显示信息
public void getInfo(String empNo){
Employee employee = new Employee();
for(int i=0;i<Emp.size();i++){
employee = (Employee) Emp.get(i);
if(employee.equals(empNo)) break;
}
System.out.println("工号为"+empNo+"的员工信息:");
System.out.println("姓名"+employee.getName());
System.out.println("年龄"+employee.getAge());
System.out.println("薪资"+employee.getSal());
System.out.println();
}
//打印所有员工信息
public void getAll(){
for(int i=0;i<Emp.size();i++){
Employee employee = (Employee) Emp.get(i);
System.out.println("工号为"+employee.getEmpNo()+"的员工信息:");
System.out.println("姓名"+employee.getName());
System.out.println("年龄"+employee.getAge());
System.out.println("薪资"+employee.getSal());
System.out.println();
}
}
//修改薪水
public void updateSal(String empNo,float sal){
Employee employee = new Employee();
for(int i=0;i<Emp.size();i++){
employee = (Employee) Emp.get(i);
if(employee.equals(empNo)) break;
}
employee.updateSal(sal);
}
//删除员工
public void remove(String empNo){
Employee employee = new Employee();
for(int i=0;i<Emp.size();i++){
employee = (Employee) Emp.get(i);
if(employee.equals(empNo)) break;
}
Emp.remove(employee);
}
//按工资排序
public void sortOnSal(){
ArrayList temp = new ArrayList();
Employee employee = new Employee();
float temp2 ;
employee = (Employee) Emp.get(0);
temp.add(employee);
float sal;
for(int i=1;i<Emp.size();i++){
employee = (Employee) Emp.get(i);
sal = employee.getSal();
for(int j=0;j<temp.size();j++){
temp2 = ((Employee) temp.get(j)).getSal();
if(sal>temp2){
temp.add(j, employee);
break;
}
if(j == temp.size()-1){
temp.add(employee);
}
}
}
for(int i=1;i<=temp.size();i++){
employee = (Employee) temp.get(i-1);
System.out.println(i+": 工号:"+employee.getEmpNo()+" 姓名"+employee.getName()+"年龄"+employee.getAge()+"薪资"+employee.getSal());
}
}
}
错误信息
java.lang.CloneNotSupportedException: interfaces.Employee
at java.lang.Object.clone(Native Method)
at interfaces.Employee.clone(Employee.java:19)
at interfaces.interfaceTestEmployees.main(interfaceTestEmployees.java:13)
我看韩顺平的视频的时候虽然他的代码也有提示叹号,但是却没有出错。
代码质量求轻喷0.0
private ArrayList Emp = null;
public EmpManager(){
Emp = new ArrayList();
}
//添加雇员
public void addEmp(Employee employee){
Emp.add(employee);
}
//根据编号显示信息
public void getInfo(String empNo){
Employee employee = new Employee();
for(int i=0;i<Emp.size();i++){
employee = (Employee) Emp.get(i);
if(employee.equals(empNo)) break;
}
System.out.println("工号为"+empNo+"的员工信息:");
System.out.println("姓名"+employee.getName());
System.out.println("年龄"+employee.getAge());
System.out.println("薪资"+employee.getSal());
System.out.println();
}
//打印所有员工信息
public void getAll(){
for(int i=0;i<Emp.size();i++){
Employee employee = (Employee) Emp.get(i);
System.out.println("工号为"+employee.getEmpNo()+"的员工信息:");
System.out.println("姓名"+employee.getName());
System.out.println("年龄"+employee.getAge());
System.out.println("薪资"+employee.getSal());
System.out.println();
}
}
//修改薪水
public void updateSal(String empNo,float sal){
Employee employee = new Employee();
for(int i=0;i<Emp.size();i++){
employee = (Employee) Emp.get(i);
if(employee.equals(empNo)) break;
}
employee.updateSal(sal);
}
//删除员工
public void remove(String empNo){
Employee employee = new Employee();
for(int i=0;i<Emp.size();i++){
employee = (Employee) Emp.get(i);
if(employee.equals(empNo)) break;
}
Emp.remove(employee);
}
//按工资排序
public void sortOnSal(){
ArrayList temp = new ArrayList();
Employee employee = new Employee();
float temp2 ;
employee = (Employee) Emp.get(0);
temp.add(employee);
float sal;
for(int i=1;i<Emp.size();i++){
employee = (Employee) Emp.get(i);
sal = employee.getSal();
for(int j=0;j<temp.size();j++){
temp2 = ((Employee) temp.get(j)).getSal();
if(sal>temp2){
temp.add(j, employee);
break;
}
if(j == temp.size()-1){
temp.add(employee);
}
}
}
for(int i=1;i<=temp.size();i++){
employee = (Employee) temp.get(i-1);
System.out.println(i+": 工号:"+employee.getEmpNo()+" 姓名"+employee.getName()+"年龄"+employee.getAge()+"薪资"+employee.getSal());
}
}
}
错误信息
java.lang.CloneNotSupportedException: interfaces.Employee
at java.lang.Object.clone(Native Method)
at interfaces.Employee.clone(Employee.java:19)
at interfaces.interfaceTestEmployees.main(interfaceTestEmployees.java:13)
我看韩顺平的视频的时候虽然他的代码也有提示叹号,但是却没有出错。
代码质量求轻喷0.0