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

I need help with the code for an ATM machine ..... In this project you implement

ID: 3761109 • Letter: I

Question

I need help with the code for an ATM machine .....

In this project you implement a computer model for bank account transactions carried out at an ATM machine. The program must perform the following functions.

• Clients are repeatedly offered three options (i) Open a new account (ii) Use an existing account previously opened (iii) Abort the process

• In case of (i) the client is asked to make a deposit to the new account and a PIN code is issued by the program as the sole identification of the account owner. The PIN must be randomly selected between 1000 and 9999 (a four digit number). The client must remember the PIN, the program only reveals it once at the opening of the account • In case of (ii) the previously issued PIN can be used at other ATM machines as well

• For both options (i) and (ii) the client can repeatedly make transactions if desired and if so the client can decide whether it will be a deposit or withdrawal • Withdrawal is limited to the current account balance; deposit can be made by inserting dollar bills of values 1, 5, 10, 20, 50, 100

• After every transaction the client is notified of the new balance

In case of option (iii) the program terminates   

Analysis and Design

The input values include

the selections of various options

the dollar value at a direct deposit

dollar bill values at an ATM deposit

Output values

messages as a result of a selected option

the dollar value of the account balance

Pseudo-code

-- while clients require service repeat

            ask for a selection of options (i), (ii) or (iii)

(i)ask for the deposit value

if accepted issue a PIN

(ii)check if account exists

if so ask for a transaction

if not offer the options again

(i)terminate the process

            while transaction required repeat

                        ask for transaction

                                    if declined stop the loop

                                    otherwise execute transaction

1.The Applications class contains the main method which in turn controls the logic of the program as described by the pseudo-code above. This class communicates with the client regarding the choices the client must make

2.The Account class represents the bank account. The class contains all the data and operations necessary for transactions

The ATM class represents the ATM machine. This class communicates with the client when a transaction is carried out. In order to execute the transactions this class must have access to the Account class methods

Explanation / Answer

import java.util.ArrayList;
import java.util.Scanner;

public class BankMain
{
private double availableBalance =80;
private double totalBalance =100;

static ArrayList<Integer> cardNum = new ArrayList<Integer>();
static Scanner input = new Scanner(System.in);

private String error;
{
error = "error";
}
public static void cardNumbers()
{
Scanner input = new Scanner(System.in);
try{

System.out.println("Please enter 5 digit card number");
int num = input.nextInt();
checkNumber(num);
}
catch(invalidNumber err){

System.out.println(" Error: " + err.getError());
contC();
}
}
public static void contC(){
Scanner keyboard = new Scanner(System.in);
System.out.println("Type 'c' to enter number again.");

String value = keyboard.next();
if(value.equalsIgnoreCase("c")){
cardNumbers();

}

else if (!keyboard.equals('c')){

System.out.println("Invalid Entry!");
}
}
public static void menu(){

System.out.println("ATM Menu:");
System.out.println();
System.out.println("1 = Account Creation");
System.out.println("2 = Login Account");
System.out.println("3 = Exit ATM");
query();
}

public void startAtm()
{
menu();
}
public void drawMainMenu()
{
AccountMain main3 = new AccountMain();
int selection;

System.out.println(" ATM main menu:");
System.out.println("1 - View account balance");
System.out.println("2 - Withdraw Amount");
System.out.println("3 - AddAmount");
System.out.println("4 - Back to Menu");
System.out.println("5 - close transaction");
System.out.print("Choice: ");
selection = input.nextInt();

switch(selection)
{
case 1:
viewAccountInfo();
break;
case 2:
withdraw();
break;
case 3:
addFunds();
break;
case 4:
AccountMain.selectAccount();
break;
case 5:
System.out.println("Thank you for using ");
}
}

public void viewAccountInfo()
{
System.out.println("Account Information:");
System.out.println(" --Total balance: $"+totalBalance);
System.out.println(" --Available balance: $"+availableBalance);
drawMainMenu();
}

public void deposit(int depAmount)
{
System.out.println(" Insert your money now ");
totalBal =totalBalance +depAmount;
availableBalance =availableBalance +depAmount;
}

public void checkNsf(int withdrawAmount)
{
if(totalBalance -withdrawAmount < 0)
System.out.println("Error because insufficent bal");
else
{
totalBalance =totalBalance -withdrawAmount;
availableBalance =availableBalance -withdrawAmount;
System.out.println(" Please collect your money ");
}
}

public void addFunds()
{
int addSelection;

System.out.println("Deposit funds:");
System.out.println("1 - $20");
System.out.println("2 - $40");
System.out.println("3 - $60");
System.out.println("4 - $100");
System.out.println("5 - Back to main menu");
System.out.print("Choice: ");
addSelection =input.nextInt();

switch(addSelection)
{
case 1:
deposit(20);
drawMainMenu();
break;
case 2:
deposit(40);
drawMainMenu();
break;
case 3:
deposit(60);
drawMainMenu();
break;
case 4:
deposit(100);
drawMainMenu();
break;
case 5:
drawMainMenu();
break;
}
}

public void withdraw()
{
try{


int withdrawSelection;

System.out.println("Withdraw :");
System.out.println("1 - $20");
System.out.println("2 - $40");
System.out.println("3 - $60");
System.out.println("4 - $100");
System.out.println("5 - Back to main menu");
System.out.print("Choice: ");
withdrawSelection =input.nextInt();

switch(withdrawSelection)
{
case 1:
checkAmount(20);
drawMainMenu();
break;
case 2:
checkAmount(40);
drawMainMenu();
break;
case 3:
checkAmount(60);
drawMainMenu();
break;
case 4:
checkAmount(100);
drawMainMenu();
break;
case 5:
drawMainMenu();
break;
default:   
System.out.println("Invalid choice.");
withdraw();
}

}
catch(invalidAmount err){
System.out.println(" Error: " + err.getError());
viewAccountInfo();
}
}

public static void query(){

Scanner keyboard = new Scanner(System.in);


while (!keyboard.hasNextInt()) {
System.out.println("Invalid choice.");
menu();
}
int input = keyboard.nextInt();

if (input == 2){

BankMainPart2 main2 = new BankMainPart2();

System.out.println(" enter your 5 digit card number.");
BankMainPart2.loginCard(cardNum);
}
else if (input == 1){

cardNumbers();
}
else if (input == 3){
System.out.println("Thank you ");
System.exit(0);
}
}


private static void checkNumber(int num) throws invalidNumber

{
Scanner keyboard = new Scanner(System.in);

if(String.valueOf(num).length()!=5)
{
throw new invalidNumber("invalid number");
}
else {

cardNum.add(num);

System.out.println(" You're card number is " +num);
contC2();
}
}
private void checkAmount(int withdrawAmount) throws invalidAmount

{
if(totalBalance -withdrawAmount < 0)
{   
throw new invalidAmount(" ");
}
else
{
totalBalance =totalBalance -withdrawAmount;
availableBalance =availableBalance -withdrawAmount;
System.out.println(" Please collect your money ");
}
}
public static void contC2(){
Scanner keyboard = new Scanner(System.in);
System.out.println("Type 'c' to return to main menu.");

String value = keyboard.next();
if(value.equalsIgnoreCase("c")){
menu();
}
else if (!keyboard.equals('c')){
System.out.println("Invalid Entry!");
contC2();
}
}
public static void main(String args[])
{
BankMain myAtm = new BankMain();
BankMainSub sub = new BankMainSub();
myAtm.startAtm();
}
}