So I have an assignment where I have to make a bank account. Long story short I have a class that has your actions (deposit, withdraw etc) in methods, and a Driver which would fills in the blanks (i.e client name, balance etc.) as well it calls the methods from the other class.
Now my issue. For an example, when I deposit, my variables send fine to the method and do the math correctly and have the correct balance, but returning the balance's new value is an issue. It is still the same value it was before in the driver.
This is my driver's deposit code
String deposit1 = JOptionPane.showInputDialog ("How much would you like to deposit?");
int deposit = Integer.parseInt (deposit1);
myBank.getDeposit(deposit, balance);
This is my deposit method code
public void getDeposit(int deposit, int balance)
{
if (deposit<0)
{
System.out.println ("Invalid Number");
deposit=0;
}
balance =balance + deposit;
}
Any help would be greatly appreciated, can't seem to find any solutions and I've been stuck for some time
Thanks
P.S This is my first time on these forums so sorry if I did anything wrong
P.P.S My java knowledge isn't that high, still just a beginner
Edit: We have learned instance variables as well as touched a little upon return statements, we haven't learned anything about passby. By return I mean giving the driver the correct value, sorry if that threw you off
Edit2: Thank youuu so much user1710742, finally got it. I understand now. Makes sense