我在使用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