0
votes

I'm new to java and I'm writing an ATM program where user can enter pin code three times and if they fail to enter the correct one, their card is blocked. I've tried to write a Junit test for the following code but I couldn't seem to figure it out. I have two classes AtmPin and AtmTester. AtmTester is where the main class is.

AtmPin.java

import java.util.Scanner;

public class AtmPin {

   public static boolean validPIN(int user, int orignal){

      

       return user==orignal;

   }

   public static int getPin(Scanner sc){

      

       System.out.print("Enter PIN: ");

       int pin = sc.nextInt();

       return pin;

   }

  
}

AtmTester.java

package atm;

import java.util.Scanner;

public class ATMTester {
     public static void main(String[] args) {

          

           Scanner keyboard = new Scanner(System.in);

           int i = 0, userpin;

          int PIN = 1234;
          while(i< 3){

              

               userpin = AtmPin.getPin(keyboard);

              

               if(AtmPin.validPIN(userpin, PIN)){

                   System.out.println("Your PIN is correct");

                   System.exit(0);

               }
               else {
                   System.out.println("Your PIN is incorrect");
               }
              

               i++;

           }

          

           System.out.println("Your Bank Card is blocked");

       }

}