我该如何解决这个错误?需要双倍,双倍;发现双重;

时间:2017-01-24 18:17:30

标签: java object

public class Account{

//实例变量

private double balance;
private double interestRate;

//构造

public void Account(double initialBalance) {
     if (balance < 0) {
     balance = initialBalance;
     }
}

public void Account() {
     balance = 0.0;
}

//实例方法

public void withdraw(double amount) {
     double backup = balance;
     balance = balance - amount;
     if (balance < 0) {
          System.out.println("error");
          balance = backup;
     }
}

//用于撤销的方法

public void deposit(double amount) {
      balance = balance + amount;
      if (balance >= 10000){
           System.out.println("You are now rich");
      }
}

public double getBalance() {
     return balance;
}

public double setInterest(double rate){
     interestRate = rate;
}

public double computeInterest (int n) {
     double computeInterest = Math.pow(interestRate + balance * n);
     return computeInterest; 

}

//此方法包含错误,并说它需要两个双打但只能//找到一个

public void close() {
     balance = 0.0;
}

//用于关闭余额的方法

}

2 个答案:

答案 0 :(得分:2)

您在Math.pow()方法中仅向computeInterest()提供了一个参数。它需要两个双打。

答案 1 :(得分:2)

更改此行:

update

使用以下行

double computeInterest = Math.pow(interestRate + balance * n);

double computeInterest = Math.pow(interestRate + balance , n); 有两个参数。第一个参数是基数,第二个参数是指数,它返回Math.pow(a,b)。所以当你只传递一个参数

时,你会收到错误