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,21 @@
public class Employee5 {
String name;
int employeeID;
protected int salary;
public Employee5(String name, int employeeID) {
this.name = name;
this.employeeID = employeeID;
}
public Employee5(String name, int employeeID, int salary) {
this.name = name;
this.employeeID = employeeID;
this.salary = salary;
}
public String toString() {
return "Name: " + name + ", Employee ID: "
+ employeeID + ", Salary: " + salary;
}
}

View File

@@ -0,0 +1,12 @@
public class Ex5 {
public static void main(String[] args) {
Employee5[] emps = new Employee5[4];
emps[0] = new Employee5("Sam", 111, 30000);
emps[1] = new PartTimer("Ray", 222, 30, 300);
emps[2] = new NewPartTimer("June", 333, 40, 100, 0.05);
emps[3] = new NewPartTimer("May", 444, 100, 100, 0.05);
for (Employee5 employee : emps)
System.out.println(employee);
}
}

View File

@@ -0,0 +1,29 @@
public class NewPartTimer extends PartTimer{
protected int mpf;
protected double mpfRate;
NewPartTimer(String name, int employeeID, int workingHour, int hourlyRate, double mpfRate){
super(name, employeeID, workingHour, hourlyRate);
this.mpfRate = mpfRate;
calculateMpf();
}
protected void calculateMpf(){
if(salary >= 6500){
mpf = (int)(salary * mpfRate);
if(mpf > 1250)
mpf = 1250;
salary = salary - mpf;
}else
mpf = 0;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString() + ", MPF Rate: " + mpfRate + "%, MPF: " + mpf;
}
}

View File

@@ -0,0 +1,21 @@
public class PartTimer extends Employee5 {
protected int workingHour;
protected int hourlyRate;
PartTimer(String name, int employeeID, int workingHour, int hourlyRate){
super(name, employeeID);
this.workingHour = (workingHour > 220) ? 0: workingHour;
this.hourlyRate = hourlyRate;
calculateSalary();
}
protected void calculateSalary(){
salary = workingHour * hourlyRate;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString() + ", Salary: " + salary + ", working Hour: " + workingHour + ", Hourly rate: " + hourlyRate;
}
}