我在使用Inheritance构造类,并且在使用super()
时遇到了困难。我有InterestCalculator class
这是CompoundInterest Class
的母公司。我想在复利class.Your构造使用super()
InterestCalculator需要3 paramenters(本金,的InterestRate和长期) 我需要调用CompoundInterest
这需要4 parameters
,我需要通过3( PrincipalAmount,InterestRate和Term)和4th parameter
特定于CompoundInterest
。java在继承中使用super()
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;
}
}
你只是补差。为什么不学习语言? – EJP 2013-05-07 03:29:17
看来你正在编写一个不知道java的构造函数。请阅读http://docs.oracle.com/javase/tutorial/java/IandI/super.html – Drogba 2013-05-07 03:30:06