我正在制作使用继承的 Construct 类,但我很难使用super()
. 我有InterestCalculator class
那个是CompoundInterest Class
. 我正在尝试super()
在 Compound Interest 类中使用。您的构造函数 InterestCalculator 需要3 个参数(本金金额、利息率和期限)
我需要调用CompoundInterest
哪个参数4 parameters
并且我需要传递3 个(PrincipalAmount、InterestRate 和期限)并且4th parameter
是特定于CompoundInterest
.
import java.util.Scanner;
public class InterestCalculator
{
protected double principalAmount;
protected double interestRate;
protected int term;
public InterestCalculator(double principalAmount, double interestRate, int term)
{
this.principalAmount = principalAmount;
this.interestRate= interestRate;
this.term = term;
}
public double getPrincipal()
{
return principalAmount;
}
public double getInterestRate()
{
return interestRate;
}
public double getTerm()
{
return term;
}
public double calcInterest()
{
return -1;
}
protected double convertTermToYears()
{
return (this.term / 12.0);
}
protected double convertInterestRate()
{
return (this.interestRate / 100.0);
}
}
public class CompoundInterest extends InterestCalculator
{
protected int compoundMultiplier = 0;
super.CompoundInterest(double compoundMultiplier);
{
super.principalAmount = principalAmount;
super.interestRate = interestRate;
super.term = term;
this.compoundMultiplier = (int) compoundMultiplier;
}
public double calcInterest()
{
double calcInterest = (super.principalAmount *Math.pow((1.0+((super.convertInterestRate())/this.compoundMultiplier)),(this.compoundMultiplier *(super.convertTermToYears()))))- super.principalAmount;
return calcInterest;
}
}