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

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...
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
A) Which of the following sets of quantum numbers are valid (enter V) and which are...
A) Which of the following sets of quantum numbers are valid (enter V) and which are invalid for the known elements? n = 2, l = 3, ml = 0, ms = +½ : B) write the corresponding orbital notation for n = 6, l = 0?
XML and JAVA Write a Java program that meets these requirements. It is important you follow...
XML and JAVA Write a Java program that meets these requirements. It is important you follow these requirements closely. • Create a NetBeans project named LastnameAssign1. Change Lastname to your last name. For example, my project would be named NicholsonAssign1. • In the Java file, print a welcome message that includes your full name. • The program should prompt for an XML filename to write to o The filename entered must end with .xml and have at least one letter...
Automobile insurance companies require drivers they insure have a valid drivers’ license and will not pay...
Automobile insurance companies require drivers they insure have a valid drivers’ license and will not pay 100% of damage claims. Explain why.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT