A member class has id, name and payment rate. In member class make abstract method: calculateSalary(): that calculates Salary of each member in arraylist. Write another class ContractMember that extends Member
a. Provide a data member contractStart and contractEnd (LocalDateTime)
b. Provide a static constant TAXRATE and initialize it to 0.07
d. Override the method calculateSalary which calculates the salary by finding the number of days between the start and end of the contract and callculating the salary for these days @ of the rate defined earlier. The method then deducts tax from this amount @ the TAXRATE and returns the net payable amount as salary.
Build a class AdHocMember which extends the ContractMember
a. Add an instance variable status (booelan).
b.Provide getter,setter and appropriate constructor. The status of an AdHocMember is true by default
c.Override the calcualteSalary method so that it calculates the salary as done in the ContractEmployee if the status is true and returns 0 otherwise.
public abstract class Member {
private int id;
private String name;
private double paymentRate;
public abstract double calculateSalary();
public double getPaymentRate() {
return paymentRate;
}
}
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class ContractMember extends Member {
public static final double TAXRATE = 0.07;
private LocalDateTime contractStart;
private LocalDateTime contractEnd;
@Override
public double calculateSalary() {
return Duration.between(contractStart, contractEnd).get(ChronoUnit.DAYS) * getPaymentRate() * (1 - TAXRATE);
}
}
public class AdHocMember extends ContractMember {
private boolean status;
public AdHocMember() {
status = true;
}
public void setStatus(boolean status) {
this.status = status;
}
public boolean status() {
return status;
}
@Override
public double calculateSalary() {
return status ? super.calculateSalary() : 0;
}
}
Comments
Leave a comment