Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. ATM Machine 1. Write a program called ATM.java that tests a user Input (PIN n

ID: 3913777 • Letter: 5

Question

5. ATM Machine 1. Write a program called ATM.java that tests a user Input (PIN number) for ATM machine. . The Default PIN used (hard-coded) is : 12345 ENTER YOUR PIN: 98210 INCORRECT PIN. TRY AGAIN INCORRECT PIN. TRY AGAIN. ENTER YOUR PIN: 12345 PIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT Notice what happens when we type the correct PIN on the first try: ENTER YOUR PIN: 12345 PIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT 2. Now, modify the program above to count number of wrong attempts. You should lock the user out after three unsuccessful attempts. Hint: use a counter to count those false entries, and use compound condition using &8. THE BANK OF MICHELL. ENTER YOUR PIN: 101e1 INCORRECT PIN. TRY AGAIN. ENTER YOUR PIN:23232 INCORRECT PIN. TRY AGAIN ENTER YOUR PIN: 99999 OU HAVE RUN OUT OF TRIES, ACCOUNT LOCKED

Explanation / Answer

(1)

import java.util.Scanner;

public class ATM {

public static void main(String args[]) {

Scanner in=new Scanner(System.in);

int pin=12345;   //default pin number

int current;

System.out.println("WELCOME TO THE BANK OF MITCHELL");

do{ System.out.println("ENTER YOUR PIN : ");

current=in.nextInt();

if(current==pin)System.out.print("PIN ACCEPTED.YOU NOW HAVE ACCESS TO YOUR ACCOUNT");

else System.out.println("INCORRECT PIN.TRY AGAIN");

}while(current!=pin);

  

}

}

(2)modified code

import java.util.Scanner;

public class ATM {

public static void main(String args[]) {

Scanner in=new Scanner(System.in);

int pin=12345; //default pin number

int current,count=3;

System.out.println("WELCOME TO THE BANK OF MITCHELL");

do{ System.out.println("ENTER YOUR PIN : ");

current=in.nextInt();

count--;

if(current==pin)

System.out.print("PIN ACCEPTED.YOU NOW HAVE ACCESS TO YOUR ACCOUNT");

else if(count>0)

System.out.println("INCORRECT PIN.TRY AGAIN");

}while(current!=pin&&count>0);

if (count==0)

System.out.println(" YOU HAVE RUN OUT OF TRIES.ACCOUNT LOCKED.");

}

}

please upvote,if find it helpful.

Thank You!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote