JAVA Programming needs to be coded. A customer may open an account in Bank A, Ba
ID: 3797944 • Letter: J
Question
JAVA Programming needs to be coded.
A customer may open an account in Bank A, Bank B or both. For simplicity, we assume that customers can make only make one type of account, checking account. Also, customers makes at most one (0 or 1) account with a bank. An account is associated with one and only one cash card. A cash card comes with a card number from which bank_id and the associated account number can be identified. A cash card also comes with its expiration date.
Customers get an access to an ATM machine using their cash cards and enter their own transactions. We consider only withdrawals for transactions. Let's assume that each card is owned by a single customer and thus simultaneous use of the same card from different ATMs will not be considered.
Each ATM defines the maximum amount of cash a customer can withdraw per transaction. We assume ATMs never run out of cash for a withdraw request that satisfies these conditions.
The ATM reads a cash card number and checks if the card is valid. A card is valid if it is not expired and its bank id is correct for the bank associated with the ATM. If it not valid, display error message and return card to the customer. If the card is valid, the ATM Initiate authorization dialog.
Authorization dialog: The customer is requested to enter his password. The ATM verifies password with the bank. The ATM receives the result of authorization (accept/reject) from bank. For the authorization is rejected, the relevant error message is displayed and card is returned to the customer. If authorization is accepted, start transaction dialog.
Transaction dialog: When authorization is successfully completed, the customer can withdraw money by entering an amount. If the amount is not within the pre-defined transaction limit at the ATM, display an error message asking the customer to redo the transaction. Otherwise, the ATM starts the transaction by sending request to the bank. After the bank gets a withdraw request from the ATM, the bank checks if the corresponding bank account has enough money for the transaction. If the amount exceeds the limit, the transaction will fail and the bank will send an error message to the ATM. If the account has sufficient money for the transaction, the amount is reduced from the bank account, the transaction is logged against the card number at the bank, a success message is sent to the ATM, and the customer can get money dispensed from the ATM. We assume ATMs never run out of cash for a successful transaction. If the transaction is not successful due to insufficient fund from the account, an error message should be displayed. In this case, the customer will be asked to enter a different amount.
For simplicity, let's assume that after a customer received an error message about an incorrect password and a withdrawal amount exceeding the pre-defined limit at ATM or the available balance of the account, the customer will not make the same mistake.
-----------Sample Output------------
Explanation / Answer
import java.util.*; public class ATM { public static Scanner kbd = new Scanner(System.in); // The checkID method determines if acctNum is a valid account number // and pwd is the correct password for the account. If the account information // is valid, the method returns the current account balance, as a string. // If the account information is invalid, the method returns the string "error". public static String checkID(String acctNum, String pwd) { String result = "error"; // Strings a, b, and c contain the valid account numbers and passwords. // For each string, the account number is listed first, followed by // a space, followed by the password for the account, followed by a space, // followed by the current balance. 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; //loop that will count the number of login attempts //you make and will exit program if it is more than 3. //as long as oriBal equals an error. 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); //this loop will keep track of the options that //the user inputs in for the menu. and will //give the option of deposit, withdraw, or logout. 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; } } } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.