0

I have pre-defined deposit and withdrawal methods. I am however having a bit of issues coming up with methods for counting the number of deposits and successful withdrawals. Any assistance or nudge in the right direction would be great, thank you.

public double countDeposits() {
    for (double deposit=0; deposit>0;amtdeposits++) {
    }
    System.out.println(amtdeposits);
}
public double countWithdrawals() {
    if ( withdraw!="Withdraw Failed: Insufficient Amount") {
        amtwithdraw=amtwithdraw++;
        System.out.println(amtwithdraw);
    }
}
Chaosfire
  • 4,818
  • 4
  • 8
  • 23
  • I would suggest reading [how to compare stings in java](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java). Also don't put random tags on your question. – Chaosfire Jun 06 '22 at 05:50

1 Answers1

0

In your both methods the return type is double i.e; public double countDeposits() &public double countWithdrawals() but you are not returning any double in the method which i assume to be amtdeposits & amtwithdraw.

i'm assuming you want to keep track of the total number of withdrawls and deposits,You can write the condition in your main method such that the countDeposits() and countWithdrawals() methods are called only when their condition is satisfied.Then in this case the correct code would be:

public double countDeposits(double amtdeposits) {
/*you need to keep track of deposits that's why you pass the amtdeposits to 
the method*/

// you don't need this 
//for (double deposit=0; deposit>0;amtdeposits++) {}


System.out.println(amtdeposits++);
return amtdeposits;
 }

public double countWithdrawals(double amtwithdraw) {
if ( withdraw!="Withdraw Failed: Insufficient Amount") {
amtwithdraw=amtwithdraw++;
System.out.println(amtwithdraw);
return amtwithdraw;  //changes made here
  }
}
  • This is awesome, thank you very much. Just one issue I also had before, being 'withdraw' is a method, I keep getting the error 'Withdraw cannot be resolved to a variable. Is there any way we could use this 'withdraw' method in the countWithdrawals method for keeping track of withdrawals. – The Outcast Jun 06 '22 at 03:29