Build a class Member that has id, name and payment rate. Write a 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
c. Provide getters, setters and appropriate constructors
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
e. Override the toString to match the output
package payment;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class Payment {
private int id;
private String name;
private double payment_rate;
public static void main(String[] args) {
}
}
class ContractMember extends Payment{
private Date contractStart, contractEnd;
final static double TAXRATE = 0.07 ;
public double calculateSalary(Date date1, Date date2, TimeUnit timeUnit) {
long diffInMillies = contractEnd.getTime() - contractStart.getTime();
double d= (double) timeUnit.convert(diffInMillies,TimeUnit.DAYS);
return d;
}
void setContractStart(Date d){
contractStart = d;
}
void setContractEnd(Date d){
contractEnd = d;
}
Date getContractEnd(){
return contractStart;
}
Date getContractStart(){
return contractStart;
}
public String toString(){
return String.valueOf(TAXRATE) ;
}
}
Comments
Leave a comment