In: Computer Science
In Java
Create an interface GainsInterest that contains two method signatures with public access modifiers for compound daily and interestAccrued that both return BigDecimal.
Create an abstract Account class and a SavingsAccount that derives from it using best programming practices. Define an account balance that is set in the constructor of SavingAccount and passed to the constructor of the Account. SavingsAccount should implement GainsInterest, but you do not need to provide implementation for those methods beyond defining the method inside in the class and returning BigDecimal.ZERO.
GainsInterest interface:
import java.math.BigDecimal;
public interface GainsInterest {
//Two abstract methods
BigDecimal compoundDaily();
BigDecimal interestAccrued();
}
Account class:
public abstract class Account {
//Define an account balance
Double accountBalance;
//constructor of Account class
Account(Double accountBalance){
this.accountBalance =
accountBalance;
}
}
SavingsAccount class:
import java.math.BigDecimal;
public class SavingsAccount extends Account implements GainsInterest{
//constructor of SavingAccount
SavingsAccount(Double accountBalance) {
//passing to the constructor of the
Account.
super(accountBalance);
}
//implementing GainsInterest methods
@Override
public BigDecimal compoundDaily() {
return BigDecimal.ZERO;
}
@Override
public BigDecimal interestAccrued() {
return BigDecimal.ZERO;
}
}