update:demo13

This commit is contained in:
dichgrem
2026-01-21 14:35:47 +08:00
parent a7334f14dc
commit 441cb7d898
6 changed files with 392 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
package com.study.demo13;
abstract class Employee {
private String name;
protected int workDays;
public Employee(String name, int workDays) {
this.name = name;
this.workDays = workDays;
}
abstract int calculateAttendance();
boolean isExcellent() {
return calculateAttendance() >= 40;
}
public String getName() {
return name;
}
}
class FullTimeEmployee extends Employee {
public FullTimeEmployee(String name, int workDays) {
super(name, workDays);
}
@Override
int calculateAttendance() {
return workDays * 2;
}
}
class InternEmployee extends Employee {
public InternEmployee(String name, int workDays) {
super(name, workDays);
}
@Override
int calculateAttendance() {
return workDays + 5;
}
}
public class AttendanceService {
public static void main(String[] args) {
Employee fullTime = new FullTimeEmployee("张三", 22);
Employee intern = new InternEmployee("李四", 20);
Employee fullTimeLow = new FullTimeEmployee("王五", 18);
Employee internExcellent = new InternEmployee("赵六", 30);
System.out.println(fullTime.getName() + " - 出勤分: " + fullTime.calculateAttendance() + " - 是否优秀: " + fullTime.isExcellent());
System.out.println(intern.getName() + " - 出勤分: " + intern.calculateAttendance() + " - 是否优秀: " + intern.isExcellent());
System.out.println(fullTimeLow.getName() + " - 出勤分: " + fullTimeLow.calculateAttendance() + " - 是否优秀: " + fullTimeLow.isExcellent());
System.out.println(internExcellent.getName() + " - 出勤分: " + internExcellent.calculateAttendance() + " - 是否优秀: " + internExcellent.isExcellent());
}
}