mirror of
https://github.com/Dichgrem/Java.git
synced 2026-02-05 01:11:57 -05:00
58 lines
1.8 KiB
Java
58 lines
1.8 KiB
Java
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());
|
|
}
|
|
}
|