• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ATM Machine program

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic