I'm very new to programming and I'm having a bit of trouble with this code.
The program compiles just fine, but I want it to suppress the following statements after an if clause has failed (i.e. entering a negative number for the deposit amount), then initiate the scanner again so the user can input another value for the amount. At the moment, after the first if clause fails the line "Invalid amount. Try again." is printed, then proceeds to the next print line statement.
I tried editing my code to look like yours but I got some serious errors when I ran the program. It compiled fine, but when I deposited $2000, it said my balance was $175. This is with a starting balance of $2175.
Also, the else statement does not execute when I enter zero or a negative number. I will post up what my AccountTest class looks like at the moment, as well as the Account class which defines the credit and debit methods.
Also, I should mention that nothing so far has done what I wanted it to do. I want to stop the next statement from printing after the user enters zero or a negative amount for debit, and then allow them to enter another number for debit. So basically, after they enter a negative number, the statement "Invalid amount. Try again." will appear and then the user can enter another number that does not execute the if clause.
So far, these suggestions have indeed made my program look more elegant, but the program still executes the next print line statement after a zero or negative number has been entered for the debit function.
Doh, sorry Kiaamaa. I got $175 for the withdrawal function. Got a little mixed up. Your code works just fine.
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop