update,
This commit is contained in:
21
_resources/it114105/itp3914/Lab12/Ex5/Employee5.java
Normal file
21
_resources/it114105/itp3914/Lab12/Ex5/Employee5.java
Normal 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;
|
||||
}
|
||||
}
|
12
_resources/it114105/itp3914/Lab12/Ex5/Ex5.java
Normal file
12
_resources/it114105/itp3914/Lab12/Ex5/Ex5.java
Normal 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);
|
||||
|
||||
}
|
||||
}
|
29
_resources/it114105/itp3914/Lab12/Ex5/NewPartTimer.java
Normal file
29
_resources/it114105/itp3914/Lab12/Ex5/NewPartTimer.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
21
_resources/it114105/itp3914/Lab12/Ex5/PartTimer.java
Normal file
21
_resources/it114105/itp3914/Lab12/Ex5/PartTimer.java
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user