A member class has id, name and payment rate. In member class make 1 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
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 com.task;
public abstract class Member {
protected Integer id;
protected String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPaymentRate() {
return paymentRate;
}
public void setPaymentRate(Double paymentRate) {
this.paymentRate = paymentRate;
}
protected Double paymentRate;
public abstract void calculateSalary();
}
package com.task;
import java.time.Duration;
import java.time.LocalDateTime;
public class ContactMember extends Member {
private static final Double TAXRATE = 0.07;
private LocalDateTime contactStart;
private LocalDateTime contactEnd;
public ContactMember(Integer id, String name, Double paymentRate, LocalDateTime contactStart, LocalDateTime contactEnd) {
this.id = id;
this.name = name;
this.paymentRate = paymentRate;
this.contactStart = contactStart;
this.contactEnd = contactEnd;
}
public LocalDateTime getContactStart() {
return contactStart;
}
public void setContactStart(LocalDateTime contactStart) {
this.contactStart = contactStart;
}
public LocalDateTime getContactEnd() {
return contactEnd;
}
public void setContactEnd(LocalDateTime contactEnd) {
this.contactEnd = contactEnd;
}
@Override
public Double calculateSalary() {
Duration duration = Duration.between(contactStart, contactEnd);
Double salary = duration.toDays() * getPaymentRate();
return salary - salary * TAXRATE;
}
@Override
public String toString() {
return "ContactMember id=" + getId() + " name=" + getName() + " paymentRate=" + getPaymentRate() +
" contactStart=" + getContactStart() + " contactEnd=" + getContactEnd();
}
}
Comments
Leave a comment