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.

double transferAmount= (new Double(amount)).doubleValue();

That looks complicated, and I would suggest the Double.parseDouble() method.

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.

Brian O'Connor

Greenhorn

Posts: 15

posted 6 years ago

Thankyou for your help!, however i'm not too sure if those methods would work with my 2 dimensional array or would they?,sorry i'm fairly new to the whole java language =/. I will paste the full code of the ATMDataFile class to see if you think it could be done without having to make any account classes which would distrupt all the GUI's i have made. I see now that i have chosen the hard and confusing way of creating this bank account system =/. But my teacher has supplied me with this code, so i'm trying to make the best of it.

Brian O'Connor

Greenhorn

Posts: 15

posted 6 years ago

Thankyou for your help!, however i'm not too sure if those methods would work with my 2 dimensional array or would they?,sorry i'm fairly new to the whole java language =/. I will paste the full code of the ATMDataFile class to see if you think it could be done without having to make any account classes which would distrupt all the GUI's i have made. I see now that i have chosen the hard and confusing way of creating this bank account system =/. But my teacher has supplied me with this code, so i'm trying to make the best of it.

Sorry for the double post =(

Campbell Ritchie

Marshal

Posts: 57446

175

posted 6 years ago

Why have you got an array of arrays in the first place? That isn't object-oriented programming.

Functions which are doing arithmetic on numbers should use .... ummmm perhaps numbers as parameters. Why are you passing a string to a function which is going to perform a calculation. Makes no sense and is not efficient.

Campbell Ritchie

Marshal

Posts: 57446

175

posted 6 years ago

Angus Comber wrote:. . . Why are you passing a string to a function which is going to perform a calculation. . . .

Because he has been told to use a String[][].

Angus Comber

Ranch Hand

Posts: 90

posted 6 years ago

Hmmm I can't imagine a teacher would tell students to do that. I can understand them wanting students to exercise 2 dimensional arrays, but not perform calculations with strings.

Campbell Ritchie

Marshal

Posts: 57446

175

posted 6 years ago

Brian O'Connor wrote:Yeah,that's the way the teacher designed it =/

It's still not object-oriented programming.I will let you work out the Bank and OverdraftException classes for yourself.

Brian O'Connor

Greenhorn

Posts: 15

posted 6 years ago

Campbell Ritchie thanks very much mate!l, however i'm not too sure how to construct the bank class from scratch.Would it be like something below? i'm pretty confused =/ thanks again for putting up with this noob =(

Campbell Ritchie

Marshal

Posts: 57446

175

posted 6 years ago

No. You have not created a Bank class, but a BankAccount class. A Bank class would look more like thisThat is the sort of thing you might want. I have given you a public interface, and filled in only the toString() method.
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.

Campbell Ritchie

Marshal

Posts: 57446

175

posted 6 years ago

you should not try to implement such a class all at once. You should implement the fields, then try running the class. Then implement its constructor and try it out. Then implement one method at a time and try it out after each method. It makes finding errors much easier, and also it is nice to see even a little code working