git_hub_happy_hour/Employee.java
2025-01-08 23:19:45 +08:00

52 lines
1.1 KiB
Java

package com.powernode.spring6;
public class Employee {
private int id;
private String name;
private int level;
private Boolean isBoss;
private Employee(int id, String name, int level, Boolean isBoss) {
this.id = id;
this.name = name;
this.level = level;
this.isBoss = isBoss;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getLevel() {
return level;
}
public Boolean getBoss() {
return isBoss;
}
public void setBoss(Boolean boss) {
if( boss && level > 25) {
isBoss = boss;
} else if (!boss && level < 25) {
isBoss = boss;
} else {
System.out.println("boss can only be person who level is higher than 25");
}
}
public static Employee staticTest(int id, String name, int level) {
return new Employee(id, name, level, level > 25);
}
public static void main(String[] args) {
Employee employee = Employee.staticTest(1,"Dan",27);
System.out.println(employee.isBoss);
}
}