JoeyJoeJo
09-20-2004, 04:51 PM
Here is another newbie java question for you guys. I have an assignment where inside of a class I am doing banking functions. They are really simplistic equations (i.e. balance = balance - withdraw, etc). Inside my constructor I have one method that calculates the balance + a $200 deposit and then prints out. Then I have a withdraw method right below that that I want to do something like balance = balance - withdraw. In the deposit method I returned balance, but for some reason I can't get balance to come down to the withdraw method.
Here is what my code kind of looks like
public double deposit(double balance, double deposit)
{
balance = balance + deposit;
System.out.println(balance);
return balance;
}
public double withdraw(double withdraw)
{
balance = balance - withdraw;
System.out.println(balance);
return balance;
}
But when I try to compile it says cannot resolve symbols for the line balance = balance - withdraw;
This isn't my real code because this is an assignment for class. Pretty much I just need to find out how to pass variables from one method to another. Thanks a lot for your help.
Here is what my code kind of looks like
public double deposit(double balance, double deposit)
{
balance = balance + deposit;
System.out.println(balance);
return balance;
}
public double withdraw(double withdraw)
{
balance = balance - withdraw;
System.out.println(balance);
return balance;
}
But when I try to compile it says cannot resolve symbols for the line balance = balance - withdraw;
This isn't my real code because this is an assignment for class. Pretty much I just need to find out how to pass variables from one method to another. Thanks a lot for your help.