Answer to Question #281633 in Java | JSP | JSF for eeef

Question #281633

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 


1
Expert's answer
2021-12-23T00:29:41-0500
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();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog