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

When you use an automated teller machine (ATM) with your bank card, you need to

ID: 3596676 • Letter: W

Question

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 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.

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

A) Contract

B) Purpose Statement

C) Examples, making sure to include counter-examples

D) Algorithm

dont write a code i just would like you to do from A to D  

in java

Explanation / Answer

A and B :Contract and Purpose Statement:

/**
Verify The Pin Number And return the Value

@param int pinNumber
@return an int equal to 1234
*/


/**
static void main(String args[])
{
read the Data and pass value as parameter in method called Pin_verify
check the return value
if it positive
then print "Pin is correct"
otherwise
print "Pin is wrong"
}
*/

C.Counter-Examples
example1:
calling the static method to verify the pin Number
class ATM
{
int Pin_verify(int pin)
{
for(int i=1;i<=3;i++)
{
if(pin==1234)
{
return 1;
}
else if(i==3) //checking for the maximum count/trials of pin Entry
{
return -1;
}
else
{
print("WrongPin Try again");
read pin Number Again;
pin=sc.nextInt();
}
}
}
static main(String args[])
{
int retval=Pin_verify(4567);//first passing input as "Pin
Number" from main Method.
if(retval==-1)
{
print("Your Card is Blocked!"); //Return value is Negetive i.e -1
}
else
{
print("Your pin correct"); //Return value is positive i.e 1.
}
}
}
example2:
---------------------
In the above example1 i am using integer value to test the pin.

Now trying with string to test the pin The Number.

String original_pin="1234";

int count=1;

abc: /** Goto label to read pinNumber

String user_pin; /** Read from the user/console */

if(original_pin.equals(user_pin))
{
print "Pin Is valid/correct!"
break;
}
else
{
if(count!=3)
{
count++;
print "Wrong Pin Numer try again";
goto abc;
}
else
{
print "Card is Blocked";
}
}



D. Algorithm:
---------------------
1.Function Pin_validation(int pin)
2.int original_pin=1234;
3.for i=1 to 3
4. if pin==original_pin
then
5. print "your Pin is Valid/Correct.";
skip/break the Loop; //Goto End
6. else if(i==3)
then
print "Your card is Blocked";
7. else
print "Invalid Pin Number! try again";
8. endloop


Source code:
---------------------------
package Sample;
import java.util.Scanner;
public class AtmMachinePin_validation
{

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int original_pin=1234;
int pin;
int count=1;
for(int i=1;i<=count;i++)
{
System.out.println(" Please Enter The Pin Number: ");
pin=sc.nextInt();
if(pin==original_pin)
{
System.out.println("Your pin is Correct:");
break;
}
else if(count==3)
{
System.out.println("Your Bank card is Blocked ");
break;
}
else
{
System.out.println("Incorrect Pin Number! please try again");
System.out.println("You have Used "+count+" Attempt");
count++;
}
}

sc.close();

}

}

Sample Output:
-------------
1. Please Enter The Pin Number:
5688
Incorrect Pin Number! please try again
You have Used 1 Attempt
Please Enter The Pin Number:
9087
Incorrect Pin Number! please try again
You have Used 2 Attempt
Please Enter The Pin Number:
2345
Your Bank card is Blocked


2. Please Enter The Pin Number:
5678
Incorrect Pin Number! please try again
You have Used 1 Attempt
Please Enter The Pin Number:
9834
Incorrect Pin Number! please try again
You have Used 2 Attempt
Please Enter The Pin Number:
1234
Your pin is Correct:


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