Question

In: Computer Science

## Problem Description You are writing a small section of an ATM machine where you accept...

## Problem Description

You are writing a small section of an ATM machine where you accept a string that is a password and accept it or reject it. If the user tries more than three times with a bad password the card is blocked and no password will be accepted until the **resetFailedAttemptCounter** method is called. The password is provided at creation of the AtmPin. Security is a priority!

The class to implement this is referred to as **AtmPin** and consists of the following public methods:

**public AtmPin(String actualCode)** - Creates an AtmPin object with the provided code as the actual PIN

**public boolean verifyPinCode(String code)** - Accepts a string which represents the user's entry of their pin code. If the string matches the actual code provided in the constructor and the account is not blocked then the method returns true. Returns false when the code is bad OR when **isAccountLocked**() is true due to too many consecutive bad verification attempts. If an invalid code was passed or a valid code, but the account is blocked, the system will increment the number of bad password attempts.

**public boolean lastAttemptFailed()** - Returns true if the last invocation of **verifyPinCode** was unsuccessful. Underlying state is updated every time a password is passed to **verifyPinCode**. This method DOES NOT do the verification of the code, but simply is a record of whether the last attempt was successful. Note that you can submit a good password but have it rejected by the system since the account is locked (**verifyPinCode** returns false).

**public boolean isAccountLocked()** - If *more than* three consecutive attempts are made then the password is not accepted (**verifyPinCode** returns false) until **resetFailedAttemptCounter** is called.

**public void resetFailedAttemptCounter()** - Resets the number of failed attempts to zero.

Your **Program.java** should contain code to test your **AtmPin** object.

**Requirements:**

- You may not hard-code the pin in the AtmPin class, but must provide it as a constructor argument

- DO NOT STORE the user's code when attempting to verify

- **verifyPinCode** returns false when

  - code is bad

  - OR

  - when **isAccountLocked**() is true due to too many consecutive bad verification attempts

- **lastAttempt** failed should not do any comparison of actual pin to the tested pin (i.e. you cannot store the user's pin)

## Getting Started

Create the following files in the folder and add the appropriately named classes to them

1. Program.java

2. AtmPin.java

Solutions

Expert Solution

Thanks for the question, here are the two program classes you will be needing. Program is a driver class, and I wrote some test cases to check that the AtmPin class is working correctly.

Hope this helps, let me know for any help with any other questions..

=============================================================================

public class AtmPin {

   private String actualCode;
    private int attempts;
    private final int MAX_ATTEMPTS =3;
    private boolean accountLocked;
    private boolean lastAttemptFailed;

    public AtmPin(String actualCodel) {
        this.actualCode = actualCodel;
        attempts=0;
        accountLocked = false;
        lastAttemptFailed = false;
    }

    public boolean verifyPinCode(String code){
        if(attempts<MAX_ATTEMPTS && !accountLocked){
            attempts+=1;
            if(actualCode.equals(code)){
                lastAttemptFailed=false;
                return true;
            }
        }
        if(attempts==MAX_ATTEMPTS){
            accountLocked=true;
        }
        lastAttemptFailed =true;
        return false;
    }

    public boolean lastAttemptFailed(){
        return lastAttemptFailed;
    }

    public boolean isAccountLocked() {
        return accountLocked;
    }
    public void resetFailedAttemptCounter(){
        attempts=0;
        lastAttemptFailed =false;
        accountLocked=false;
    }
}

=============================================================================

public class Program {



    public static void main(String[] args) {





        AtmPin pin = new AtmPin("1234");

        System.out.println("Attempt 1: Trying to enter atm pin with incorrect pin");

        pin.verifyPinCode("1233");

        System.out.println("pin.isAccountLocked() = " + pin.isAccountLocked());

        System.out.println("pin.lastAttemptFailed() = " + pin.lastAttemptFailed());





        System.out.println("\nAttempt 2: Trying to enter atm pin with incorrect pin");

        pin.verifyPinCode("1244");

        System.out.println("pin.isAccountLocked() = " + pin.isAccountLocked());

        System.out.println("pin.lastAttemptFailed() = " + pin.lastAttemptFailed());





        System.out.println("\nAttempt 3: Trying to enter atm pin with incorrect pin");

        pin.verifyPinCode("1224");

        System.out.println("pin.isAccountLocked() = " + pin.isAccountLocked());

        System.out.println("pin.lastAttemptFailed() = " + pin.lastAttemptFailed());



        System.out.println("\nAttempt 4: Trying to enter atm pin with incorrect pin");

        pin.verifyPinCode("1222");

        System.out.println("pin.isAccountLocked() = " + pin.isAccountLocked());

        System.out.println("pin.lastAttemptFailed() = " + pin.lastAttemptFailed());





        System.out.println("\nResetting the counter now..");

        pin.resetFailedAttemptCounter();





        System.out.println("\nAttempt 5: Trying to enter atm pin with correct pin");

        pin.verifyPinCode("1234");

        System.out.println("pin.isAccountLocked() = " + pin.isAccountLocked());

        System.out.println("pin.lastAttemptFailed() = " + pin.lastAttemptFailed());

    }





}

Related Solutions

writing a program that will act like an ATM machine by the end of this course....
writing a program that will act like an ATM machine by the end of this course. In order to access the ATM, the customer must enter their user name and their passcode. After 3 incorrect attempts at entering the user name and password, the program will end. The list of legitimate users along with their user ID, passcode and account balance will be provided to you. There are only 5 functions that can be carried out by the ATM: 1...
Question: PROJECT 2 – ATM MACHINE For this project you will be building an ATM application...
Question: PROJECT 2 – ATM MACHINE For this project you will be building an ATM application that will allow ... PROJECT 2 – ATM MACHINE For this project you will be building an ATM application that will allow users to log in, deposit, withdraw, and check balance. Set a default beginning balance of $1000. I want all monies formatted to currency. Log in Usernames and passwords need to be stored in parallel arrays. At least three logins available for me....
Excel and Writing Case Assignment Description: ABC Corporation has a machine that requires repairs or should...
Excel and Writing Case Assignment Description: ABC Corporation has a machine that requires repairs or should be replaced. ABC has evaluated the two options and calculated the cash flows resulting from each option as follows: Option A: Repair the Machine Year Cash Flow 0 -50,000 1 15,500 2 20,100 3 18,900 4 17,100 5 13,700 Year Cash Flow Option B: Buy a new Machine Cash Flow 0 -400,000 1 51,300 2 155,000 3 127,800 4 126,900 5 125,100 You have...
I have an ATM Machine program. I'm not sure where to place the:   public void io() {...
I have an ATM Machine program. I'm not sure where to place the:   public void io() { section so the program gives the following output: Welcome to ATM Press Enter to begin; Enter amount to begin: Enter amount to withdraw: 230 Cash dispensed as follows: $100 Bills: 2 $20 Bills: 1 $10 Bills: 1 The progam consists of Main.java class Main { public static void main(String[] args) { ATM atm = new ATM(); atm.init(); atm.run(); System.out.println(); System.out.println("ATM Version 0.1.0"); System.out.println("Copyright (C)...
You will be writing a small bank application. There will be two applications to this project...
You will be writing a small bank application. There will be two applications to this project – a client and a teller / administrative application with different functionalities between the two. As their names suggest, the client application will be tailored for customers of the bank, and the other for the employees of the bank. For your client side application, a client should be able to “log into” the program by providing a social security number. The program should only...
You will write a program using Python that simulates an Automatic Teller Machine (ATM). For this...
You will write a program using Python that simulates an Automatic Teller Machine (ATM). For this program, your code can have user defined functions (but not required), the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Requirements: There is a customer with the following credential and can only access the system if the Access Code is correct: • Name: Peter Parker, Access Code: 2222 • When the program...
Problem Description: Game: Bean Machine or Galton Box To figure out if the ball falls to...
Problem Description: Game: Bean Machine or Galton Box To figure out if the ball falls to Left or Right, you can generate a random number using Math.random(). If this random number is greater than or equal to 0.5 we assume the ball falls to the Right otherwise it falls to the Left (or vise versa). If there are 8 slots, the ball should hit 7 nails (8 -1), thus you should run a loop 7 times to figure out the...
Suppose you own a small business. Why might it be more beneficial to accept: debit or...
Suppose you own a small business. Why might it be more beneficial to accept: debit or cash versus a credit or check payment?
Make a Console application Language should be Visual Basic You will be simulating an ATM machine...
Make a Console application Language should be Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount. If the user enter more than...
When you use an automated teller machine (ATM) with your bank card, you need to use...
When you use an automated teller machine (ATM) with your bank card, you need to use a personal identification number (PIN) to access your account. If a user fails more than three times when entering the PIN, the machine will block the card. Assume that the user's PIN is "1234" and write a program in python that asks the user for the PIN no more than three times, and does the following: 1. If the user enters the right number,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT