Employee类
* @Author ChenJiahao(程序员五条)
* @Date 2021/9/21 19:28
*/
public class Employee implements Comparable<Employee>{
private int id;
private String name;
private double salary;
public Employee() {
}
public Employee(int id, String name, double salary) {
this.id = id;
this.name = name;
this.salary = salary;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
@Override
public String toString() {
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
", salary=" + salary +
'}';
}
@Override
public int compareTo(Employee o) {
if(this.id < o.id){
return -1;
}else if (this.id > o.id){
return 1;
}else{
return 0;
}
}
}
Manager类
/**
* @Author ChenJiahao(程序员五条)
* @Date 2021/9/21 19:30
*/
public class Manager extends Employee {
private double bonus;
public Manager() {
}
public Manager(int id, String name, double salary, double bonus) {
super(id, name, salary);
this.bonus = bonus;
}
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
@Override
public double getSalary() {
return super.getSalary() + this.bonus;
}
@Override
public String toString() {
return "Manager{" +
"bonus=" + bonus +
'}';
}
}
第四个问题不知道你具体是想干嘛