员工类, 有姓名, 年龄, 薪水三个成员属性需要私有并提供get, set方法, 可以通过构造函数进行初始化,并且按照薪水排序
自己刚写的,请问还有哪里错的吗?还有就是 return st.salary - this.salary;这一句报错 请问是什么问题?
错误是
The operator - is undefined for the argument type(s) java.lang.String, java.lang.String
看了下 貌似是参数未定义,请问怎样修改 谢谢!
- Java code
public class staff implements Comparable { private String name; private int age; private String salary; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSalary() { return salary; } public void setSalary(String salary) { this.salary = salary; } @Override public int compareTo(Object obj) { if (obj instanceof staff) { staff st = (staff) obj; return st.salary - this.salary; } return -1; }}
------解决方案--------------------
晕,LZ的salary是String类型的,String类型当然不能用 - 处理了
把salary改成double类型
- Java code
//private String salary;private double salary; //public String getSalary() { public double getSalary() { return salary; } //public void setSalary(String salary) { public void setSalary(double salary) { this.salary = salary; }