繁体   English   中英

我该如何解决此错误? 要求加倍,加倍; 发现双;

[英]How do i fix this error? required double, double; found double;

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

//用来关闭余额的方法

}

您仅在您的computeInterest()方法中给Math.pow()一个参数。 它需要两个双打。

更改此行:

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

与以下行

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

Math.pow(a,b)两个参数。 第一个参数是基数,第二个参数是指数,它返回a^b 因此,当您仅传递一个参数时,就会收到错误消息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM