Problem Description

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 users PIN is 1234 and write a program that asks the user for the PIN no more than three times, and does the following:

  • If the user enters the right number, print a message saying, Your PIN is correct, and end the program.
  • If the user enters a wrong number, print a message saying, Your PIN is incorrect and, if you have asked for the PIN less than three times, ask for it again.
  • If the user enters a wrong number three times, print a message saying Your bank card is blocked and end the program.

Part 1: Problem-Solving Phase

Using the Design Recipe, write each of the following for this problem:

1.Contract
2.Purpose Statement
3.Examples, making sure to include counter-examples
4.Algorithm

Make sure to test your algorithm by hand with the examples to verify it before continuing to Part 2.

Part 2: Implementation Phase

Using Eclipse, write the Java program for the algorithm formulated in Part 1, and test your program with the examples from Part 1. Make sure to incorporate your Contract, Purpose Statement and Examples as one or more comment blocks, and your Algorithm as line comments in your Java source code.

Extra Credit

You will be awarded 10 additional points each for implementing the following methods, and using (calling) them in the program (main method):

  • getPin(Scanner) -> int
    method uses the Scanner parameter variable to get and return user input of a PIN method returns 0 if invalid input is entered; invalid input includes both 0 or negative integers, or non-integer input
  • validPIN(int, int) -> boolean
    method checks the validity of the given PIN (first parameter variable) against the correct PIN (second parameter variable), and returns a boolean indicating this validity
  • Note that to earn the 10 additional points for each method, it must be designed and documented using the Design Recipe; this is described in the document Using the Design Recipe to Write Modular Computer Programs.

Sample Run (user input in color)

Welcome to Java Banking
Enter your PIN: abc
Your PIN is incorrect
Enter your PIN: 123
Your PIN is incorrect
Enter your PIN: 1234
Your PIN is correct
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.