This commit is contained in:
louiscklaw
2025-01-31 19:15:17 +08:00
parent 09adae8c8e
commit 6c60a73f30
1546 changed files with 286918 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
public class PartTimeStaff extends Staff implements Salary {
private int workingHour;
public PartTimeStaff(String name, int id, char grade, int workingHour) {
super(name, id, grade);
this.workingHour = workingHour;
}
public void display() {
System.out.println("Name: " + name + "; ID: " + id + "; Grade: " + grade + "; Working Hour: " + workingHour + "; Salary: " + computeSalary());
}
public int computeSalary() {
switch (grade) {
case 'A':
return SALARY_A;
case 'B':
return SALARY_B;
case 'C':
return SALARY_C;
default:
return SALARY_OTHER;
}
}
}

View File

@@ -0,0 +1,8 @@
public interface Salary {
public final int SALARY_A = 4000;
public final int SALARY_B = 3000;
public final int SALARY_C = 2000;
public final int SALARY_OTHER = 1000;
public abstract int computeSalary();
}

View File

@@ -0,0 +1,13 @@
public abstract class Staff {
protected String name;
protected int id;
protected char grade;
public Staff(String name, int id, char grade) {
this.name = name;
this.id = id;
this.grade = grade;
}
public abstract void display();
}

View File

@@ -0,0 +1,8 @@
public class TestStaff {
public static void main(String args[]) {
PartTimeStaff p1 = new PartTimeStaff("John", 123, 'B', 20);
PartTimeStaff p2 = new PartTimeStaff("Mary", 124, 'A', 22);
p1.display();
p2.display();
}
}