i wrote this piece of code
I’m not sure on how to approach this problemCode:public class CheckBankAccount{ public static void main(String[] argv) { int pinNo, userTries, counter; float cashAmount; // Start of an endless loop since cashpoints never sleep. do { // Users name should appear BankAccount b = new BankAccount("James",1234); System.out.println(b.getName()); // set the try counter to zero counter = 0; // loop to check max. 3 times for correct PIN starts here. do { //ask user for PIN. System.out.println("Please enter your PIN"); // user enters PIN into the pinNo variable. pinNo = UserInput.readInt(); if (pinNo == 9999){ System.out.println ("bye"); System.exit(0); } // increment counter for tries ++ counter; // end of the 'do' loop. Use a while here that checks if the PIN is incorrect AND // the counter for tries is smaller than 3 } while( (pinNo != 1234) && (counter < 3) ); // this part of the program only executes if the counter for tries is smaller than 3 // Use an if statement here that checks that. if (counter < 3) { // Ask how much the user wants to withdraw. System.out.println("How much do you want to withdraw?"); // User enters amount. cashAmount = UserInput.readFloat(); // Print message confirming transaction: "You have withdrawn xxx Pounds" System.out.println(" has withdrawn " +cashAmount+ " Pounds"); // end of the if statement } // end of the endless 'do'-'while' loop. } while (true); } // end of main } // end class
if the user inputs the wrong PIN this message should appear
"Invalid PIN, please try again"
if the user inputs the PIN incorrect 3 times this message should appear.
"3 x invalid PIN: aborting"
and exit the program using the System.exit(0) function
any ideas???




Reply With Quote