Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ATM Machine program  RSS feed

 
Jay Poole
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to figure out what is going wrong with this program I'm writing. Heres the full description of what I'm trying to do: Use the Account class created in Programming Exer- cise 9.7 to simulate an ATM machine. Create ten accounts in an array with id 0, 1, . . . , 9, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. Thus, once the system starts, it will not stop.

When I go to check balance it will re loop me back to the scanners for id and choice. I'm not sure what the problem is here, can someone try to run my code or give me some insight on what might be the problem. Thanks. The program is supposed to be able to go through any choice of transactions, simulating an ATM machine, the id being a number between 0-9. Here is the new updated code.



 
Peter Muster
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't take this offensive but have you ever used a Debugger in Java?

After printing "The balance is..." message the condition of the loop "while (enterchoice != 4)" will be evaluated again, and as it is still true mainMenu() will be called which prints exactly what you have stated. The next lines in your while loop will ask for id and choice again.

you should really try to use a Debugger and set a breakpoint at the system.out.println statement for your balance message, then check the flow of the program step by step. If you use Eclipse you can jump a single step by pressing F6 key and enter methods such as mainMenu() by pressing F5 key.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Poole wrote:I have been trying to figure out what is going wrong with this program I'm writing. Heres the full description of what I'm trying to do: Use the Account class created in Programming Exer- cise 9.7 to simulate an ATM machine.

And yet you've called your class 'test', which is wrong immediately, because class names should start with a CAPITAL letter.
What's wrong with 'ATM'?

It seems that you've been given a fairly clear set of instructions, but I suspect that you've written far too much code before you started testing.
You might want to have a look at this article, because it gives you some tips on how to set up a new class that you may find useful.

You should also get rid of as many of those static members as possible (methods AND variables). And you can find out how to do that here.

HIH

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!