• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble Reading and Writing to a file.  RSS feed

 
Matthew McLandyn
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot figure out what I am missing on this school assignment. I will preface my request for help by saying that I don't want this done for me, I want to understand whats going on here and what I am doing wrong.

I have accountsData.txt file in my default package, this is the file it should be writing to and reading from.

There is an ATM class, which has the main in it. From here the program is supposed to work like an atm, you type in your account number and can withdraw or deposit. It is supposed to then write the changes to the file.

This is my first post, so if I haven't given enough information please let me know, I appreciate any time and help!

 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added code tags, which you should always use, to your post and see how much better your post looks (). I also got rid of the colour tags and some of the blank lines.
I can't see much wrong with the reading method. I presume it works all right?

What worries me is that you are reading and writing to the same file simultaneously in the other method. I have never tried that, but I don't think it would work. Also, you appear to be reading and writing the entire file every time you have a withdrawal.
Suggeest you put a withdraw() method in your bank account class. Suggest you work out how to use a Map<Integer, Account> to enable you to find an account from its number. Suggest that you use a method to write all your accounts to the file when you have taken all your withdrawals. Not reading and writing together.
 
Matthew McLandyn
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the input! I am going to try to implement some changes this weekend!
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!