-1

継承を使用するコンストラクト クラスを作成していますが、 super(). のInterestCalculator class親である がありCompoundInterest Classます。複利クラスでを使用しようとしています。super()コンストラクター InterestCalculator は3 つのパラメーター (元金、InterestRate、および期間) を受け取ります。どのパラメーターを呼び出す必要があり、 3 つ (PrincipalAmount、InterestRate、および期間)を渡す必要がありCompoundInterestます。およびは に固有です。 4 parameters4th parameterCompoundInterest

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;    
  }
}
4

2 に答える 2

0

クラスにはいくつかのCompoundInterest間違いがあります。

1 - スーパークラス コンストラクターを呼び出す必要があります。InterestCalculatorコンストラクターは 1 つしかないため(double, double, int)、コンストラクターの先頭で呼び出す必要がありますCompoundInterest

2 - をsuper間違った方法で使用しているsuper.CompoundInterestsuperスーパークラスからメソッドにアクセスするために使用されます。名前を に変更する必要がありCompoundInterestます。

3 - 最初の項目で述べたように、スーパークラスからコンストラクターを呼び出す必要があります。次のようにしますsuper(principalAmount, interestRate);。覚えておいてください: これはコンストラクターの最初の呼び出しでなければなりません。

CompountInterest4 -期待されている 3 つのパラメーターのいずれにも渡していません。これらのパラメータCompoundInterestも同様に配置することを検討する必要があります。

これらの変更を適用すると、コードは次のようになります。

CompoundInterest(double compoundMultiplier, double principalAmount, double interestRate, int term); {
    super(principalAmount, interestRate, term);
    this.compoundMultiplier = (int) compoundMultiplier; 
}
于 2013-05-07T03:38:51.260 に答える