I'm putting the problem down to not being able to use more than 1 return statement?
By transfer function, do you mean you transfer a particular amount from one account to another? "Transfer Function" sounds like a complicated mathematical word for something complicated.
That code looks complicated. There is a lot that could be simplified. You are going to suffer the well-known imprecision of floating-point arithmetic, but have more pressing things to think of at present.
That looks complicated, and I would suggest the Double.parseDouble() method.
double transferAmount= (new Double(amount)).doubleValue();
What you want is to pass two Account objects and an amount to transfer. You withdraw it from one account and deposit it in the other. I would suggest you can get that down to five linesYou don't want to return a new balance from a transfer method; the method does not record the amount, but the Accounts do. You can alternatively use an instance method in one Account and pass the other Account, like thisIt looks to me as if you had not been taught any object-orientation. If you create Account classes, and give it withdraw, deposit and getBalance methods, you will find life much easier. You can stop messing around with arrays of arrays, and simply have an Account array.
Sorry for the double post =(
Because he has been told to use a String.
Angus Comber wrote:. . . Why are you passing a string to a function which is going to perform a calculation. . . .
It's still not object-oriented programming.I will let you work out the Bank and OverdraftException classes for yourself.
Brian O'Connor wrote:Yeah,that's the way the teacher designed it =/
You will have to work out which fields this Bank requires, how to add accounts, how to close them, how to get the total of balances, for yourself.
There are other ways you can design a Bank class.