Question

In: Computer Science

Java Requirements: The ATM system will require users to enter a valid ID . If the...

Java

Requirements: The ATM system will require users to enter a valid ID . If the entered ID matches to one of the Accounts’ ID, the system will present the user an ATM menu. The ATM menu asks the user to enter a choice, and depending on the user’s choice it may ask for additional input (i.e., withdraw or deposit amount).  The code should show for each user choice as shown in the sample-run figure at the end.  Description of the sample-run figure (shown at the end): In the main method, create an Array of ten accounts with account IDs as 1, . . . , 10, and an initial balance of $100 for each account. You will use this Array to simulate an ATM machine experience in the main method. To do that, you need a Scanner to capture the user’s input and define a few variables. You should also define a few methods in the main class, to be used inside the main method, to make the main method looks lean. Additional simulation requirements: After creating the 10-element array, the system should prompt the user to enter an ID and it will verify if the ID is a valid one. An ID is valid if it matches to one of the accounts of the 10-element Array. If the ID is valid, the ATM menu is displayed; otherwise the system will ask the user to enter a correct ID. That is, the system will not present the ATM main menu until the user enters a correct ID. Based on the above ATM simulation description, once the system starts it will not stop because after a user chooses option 4 to exit the ATM system will ask user to enter an ID again. To give users an option exiting the system after a few rounds of ATM simulation, inform users that when entering an ID, enter 0 to exit the ATM run (since valid ids are from 1 to 10). That is, if users enter 0 as ID, instead of showing the menu, the system will terminate the project, but before that it will print out every ATM transactions for each account in the Array that actually incurred transactions.

Solutions

Expert Solution

I have written the java code for the atm machine. I have created just 3 users and have given passwords for their accounts and initial limit of $100. There are options added for the user to add and retireve money from the bank accounts.

working java code:

import java.util.*;

class ATM {

public static Scanner sc = new Scanner(System.in);
public static String user_account(String acctNum, String pwd)
{
String result = "error";

// this is to store account information and password with initial amount of $100
String a = "1 pass 100";
String b = "2 pass 100";
String c = "3 pass 100";

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 user_choice;
do
{
System.out.print("\nPlease Choose From the Following Options:"
+ "\n 1. Check Balance \n 2. Add Money"
+ "\n 3. Get Money\n 4. Log Out\n\n");

user_choice = sc.nextInt();

if (user_choice < 1 || user_choice > 4){
System.out.println("error");
}

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

return user_choice;
}

public static void check_balance(double x)
{
System.out.printf("\nYour Current Balance is $%.2f\n", x);
}

public static double add_money(double x, double y)
{
double add_moneyAmt = y, account_balance = x;
double newBalance = add_moneyAmt + account_balance;

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

return newBalance;
}

public static double get_money(double x, double y)
{
double get_moneyAmt = y, account_balance = x, newBalance;

newBalance = account_balance - get_moneyAmt;
System.out.printf("Your New Balance is %.2f\n",newBalance);

return newBalance;
}

public static void main(String[] args) {

String accNum, pass, origBal = "error";
int count = 0, menuOption = 0;
double add_moneyAmt = 0, get_moneyAmt = 0, account_balance=0;
boolean foundNonDigit;
do{
foundNonDigit = false;
System.out.println("Please Enter Your Account Number: ");
accNum = sc.next();

System.out.println("Enter Your Password: ");
pass = sc.next();

origBal = user_account(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("\nYour New Balance is: $ "+ origBal);
}
else
System.out.println(origBal);


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

account_balance=Double.parseDouble(origBal);

while (menuOption != 4)
{
menuOption=menu();
switch (menuOption)
{
case 1:
check_balance(account_balance);
break;
case 2:
System.out.print("\nEnter Amount You Wish to add_money: $ ");
add_moneyAmt = sc.nextDouble();
account_balance=add_money(add_moneyAmt, account_balance);
break;
case 3:
System.out.print("\nEnter Amount You Wish to get_moneyl: $ ");
get_moneyAmt = sc.nextDouble();

while(get_moneyAmt>account_balance){
System.out.print("ERROR: INSUFFICIENT FUNDS!! "
+ "PLEASE ENTER A DIFFERENT AMOUNT: $");
get_moneyAmt = sc.nextDouble();
}

account_balance = get_money(account_balance, get_moneyAmt);
break;
case 4:
System.out.print("\nThanks for visiting. Enjoy ur day");
System.exit(0);
break;
}
}
}
}

Input given

1

pass

4

Output:


Related Solutions

11) Enter the following using Java. Use for loop to enter student id, student name, major...
11) Enter the following using Java. Use for loop to enter student id, student name, major and grades. Also grades should display their letter grades based on their conditions. After that display the name of students and their info, and also their letter grade After that display the sum of all grades and the average Output Example: Student ID: 0957644 Student Name: Pedro Hernandez Student Major: Business Information Systems Grades for Fall 2020: Introduction to Computer Science using Java: 85,...
Write a C++ program that will require users to enter an automobile VIN number and you...
Write a C++ program that will require users to enter an automobile VIN number and you will check certain aspects: The VIN number must be 17 characters exactly in length The VIN number may contain only letters and numbers The first character is the location of manufacture; we will check for this to be 1 to 5 (made in North America). The 10th character indicates the manufacture year. We will check for this being a letter between A and I...
Write a java code that ask users to pick two of the job categories and enter...
Write a java code that ask users to pick two of the job categories and enter two working areas from each category. The users must enter the start and end time for each of the two selection and calculate the hours for each category and the total hours for all the categories. If the users total hours is more that 10 hours, they are awesome, if not, they are lazy. Shor and simple code using while or for loops. Thanks...
write a program i java that ask the user to enter salary, user ID and username...
write a program i java that ask the user to enter salary, user ID and username and out put them
The requirements for a valid offer and a valid acceptance in a bilateral agreement.
The requirements for a valid offer and a valid acceptance in a bilateral agreement.
Have to write a program in Java for an ATM however when compiling after enter w...
Have to write a program in Java for an ATM however when compiling after enter w nothing happens. import java.util.Scanner; public class ATMMain {    public static void main(String[] args) {    double Ibalance = 5000, usermoney, withdrawB, depositD;    String userFname = "X";    String userLname = "X";    String w, d, e, c;    System.out.println("Welcome");    Scanner input = new Scanner(System.in);        System.out.println("Welcome" + " " + userFname + " " + userLname);        System.out.println("your current...
Some states have recently begun to implement new voter ID laws that require a photo ID...
Some states have recently begun to implement new voter ID laws that require a photo ID in order to vote, while others are loosening requirements and allowing people to vote with little or no proof of identification. The League of Women Voters is currently suing 3 states for requiring proof of citizenship to register to vote. What do you think about this? Should you have to prove you are a citizen in order to register to vote? Should voter ID...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter payroll information Employee name and create variable for scanner Hours worked Hourly pay rate Federal tax rate State tax rate Declare variable doubles for gross pay, federal, state and total deduction Display payroll statement example: Name of employee Hours worked Hourly pay rate Gross pay which is equal hours worked multiply hourly pay rate Federal withholding which is equal of gross pay multiply federal...
Simulate an ATM machine. Create ten accounts in an array with id 0, 1, . ....
Simulate an ATM machine. Create ten accounts in an array with id 0, 1, . . . , 9, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing...
Review the basic requirements for a valid contract listed at the beginning of this chapter. Now...
Review the basic requirements for a valid contract listed at the beginning of this chapter. Now consider the relationship entered into when a student enrolls in a college or university. 1. One group should analyze and discuss whether a contract has been formed between the student and the college or university. 2. A second group should assume that there is a contract and explain whether it is bilateral or unilateral
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT