asdasd
asdasd

Reputation: 11

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

public class Account{

//instance variables

private double balance;
private double interestRate;

//constructors

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

public void Account() {
     balance = 0.0;
}

//instance methods

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

//method used to withdraw

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; 

}

//this method contains the error and says it requires two doubles but can only //find one

public void close() {
     balance = 0.0;
}

//method used to close the balance

}

Upvotes: 0

Views: 2323

Answers (2)

Md Johirul Islam
Md Johirul Islam

Reputation: 5162

Change this line:

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

With the following line

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

Math.pow(a,b) takes two parameters. The first parameter is the base and the second parameter is the exponent and it return a^b. So you are getting the error as you pass only one parameter

Upvotes: 2

Kayaman
Kayaman

Reputation: 73578

You're giving only one parameter to Math.pow() in your computeInterest() method. It takes two doubles.

Upvotes: 2

Related Questions