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

JAVA (GUI) project: ATM MAchine You have two text file 1. AccountInformation.txt

ID: 3853296 • Letter: J

Question

JAVA (GUI) project:

ATM MAchine

You have two text file

1. AccountInformation.txt: will contain the Account informations. Formate of the file will be

-account number

-last name

-first name

-balance atm access status: active/disable

2. Password.txt : will contain the login information.  Format of the file will be

AccountNumber password

At first do the Login then show the menus .

You have to implement all this functionality. For each button click open a new user interface to get the appropriate data and show the result. If a user clicks on the button “Make a Transfer” you should show a GUI that has the account number and amount to transfer. You are free to add more functionality.

Important: Please note that all term projects are questions. In other words, you are free functionally and improve the user interfaces.

Account Number: Password: Login Deposit withdraw Check Balance Make a Transfer Change Password Logout

Explanation / Answer

import java.util.*;

public class ATM {

    public static Scanner kbd = new Scanner(System.in);

   

".

    public static String checkID(String acctNum, String pwd)

    {

        String result = "error";

       

        String a = "44567-5 mypassword 520.36";

        String b = "1234567-6 anotherpassword 48.20";

        String c = "4321-0 betterpassword 96.74";

        if (acctNum.equals(a.substring(0, a.indexOf(" "))) &&

                pwd.equals(a.substring(a.indexOf(" ")+1,a.lastIndexOf(" "))))

            return result = a.substring(a.lastIndexOf(" ") + 1);

        if (acctNum.equals(b.substring(0, b.indexOf(" "))) &&

                pwd.equals(b.substring(b.indexOf(" ")+1,b.lastIndexOf(" "))))

            return result = b.substring(b.lastIndexOf(" ") + 1);

        if (acctNum.equals(c.substring(0, c.indexOf(" "))) &&

                pwd.equals(c.substring(c.indexOf(" ") + 1,c.lastIndexOf(" "))))

            return result = c.substring(c.lastIndexOf(" ") + 1);

        return result;

    }

    public static int menu()

    {

        int menuChoice;

        do

        {

            System.out.print(" Please Choose From the Following Options:"

                    + " 1. Display Balance 2. Deposit"

                    + " 3. Withdraw 4. Log Out ");

            menuChoice = kbd.nextInt();

            if (menuChoice < 1 || menuChoice > 4){

                System.out.println("error");

            }

       }while (menuChoice < 1 || menuChoice > 4);

        return menuChoice;

    }

    public static void displayBalance(double x)

    {

        System.out.printf(" Your Current Balance is $%.2f ", x);

    }

    public static double deposit(double x, double y)

    {

        double depositAmt = y, currentBal = x;

        double newBalance = depositAmt + currentBal;

        System.out.printf("Your New Balance is $%.2f ", newBalance);

        return newBalance;

    }

    public static double withdraw(double x, double y)

    {

        double withdrawAmt = y, currentBal = x, newBalance;

        newBalance = currentBal - withdrawAmt;

        System.out.printf("Your New Balance is %.2f ",newBalance);

        return newBalance;

    }

    public static void main(String[] args) {

        String accNum, pass, origBal = "error";

        int count = 0, menuOption = 0;

        double depositAmt = 0, withdrawAmt = 0, currentBal=0;

        boolean foundNonDigit;

       

        do{

            foundNonDigit = false;

            System.out.println("Please Enter Your Account Number: ");

            accNum = kbd.next();

            System.out.println("Enter Your Password: ");

            pass = kbd.next();

            origBal = checkID(accNum, pass);

            count++;

            if (count >= 3 && origBal.equals("error")){

                System.out.print("Maximum Login Attempts Reached.");

                System.exit(0);

            }

            if (!(origBal.equals("error"))){

                System.out.println(" Your New Balance is: $ "+ origBal);

            }

            else

                System.out.println(origBal);

        }while(origBal.equals("error"));

        currentBal=Double.parseDouble(origBal);

        while (menuOption != 4)

        {

            menuOption=menu();

            switch (menuOption)

            {

            case 1:

                displayBalance(currentBal);

                break;

            case 2:

                System.out.print(" Enter Amount You Wish to Deposit: $ ");

                depositAmt = kbd.nextDouble();

                currentBal=deposit(depositAmt, currentBal);

                break;

            case 3:

                System.out.print(" Enter Amount You Wish to Withdrawl: $ ");

                withdrawAmt = kbd.nextDouble();

                while(withdrawAmt>currentBal){

                    System.out.print("ERROR: INSUFFICIENT FUNDS!! "

                            + "PLEASE ENTER A DIFFERENT AMOUNT: $");

                    withdrawAmt = kbd.nextDouble();

                }

                currentBal = withdraw(currentBal, withdrawAmt);

                break;

            case 4:

                System.out.print(" Thank For Using My ATM. Have a Nice Day. Good-Bye!");

                System.exit(0);

                break;

            }

        }

    }

}