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

Hi all, once again thanks for your help with this assignment, I learn a lot from

ID: 3807082 • Letter: H

Question

Hi all, once again thanks for your help with this assignment, I learn a lot from your good work. thanks inadvance.

9.1111111111 Create a new Java class inside your project folder.
The name of the class should be: ATM

Begin the assignment by erasing all of the default code that Eclipse placed into your new class, and then COPY THIS CODE and paste it into your file

For this assignment, you will be writing a java application program that simulates a fairly simple ATM machine. You will do this by adding your own code to the java file that has already been started for you. The java code already contains the beginning of a method that you will need to finish writing. In addition, you will need to add the main program code and some methods of your own.

1.Your program should perform the following steps, in the order listed:

2.Your program should begin by asking the user for an account number. The user is expected to enter an account number and then press enter.

3.Next, your program should ask the user to enter the account's password. The user is expected to enter a password and then press enter.

.Next, you should call on the checkID method, giving it the account and password entered by the user, to determine if they are correct.

If the information is correct, the method should return the account balance for the account.
If the information is incorrect, you should display an error message and return to step 2.

NOTE: You should only allow the user a total of three attempts to type the account number and password. If the information is still incorrect after the third attempt, you should display an error message saying something about the maximum number of attempts being reached, then stop the program.

4.Next display a menu on the screen allowing the user to make a choice from the following options:

1.Display Balance

2.Deposit

3.Withdraw

4.Log Out

5.If the user does not enter option 1, 2, 3, or 4, you should display an error message, display the menu again, and ask for another option to be entered.

6.If the user chooses option 1, you should show the account balance on the screen.

7.If the user chooses option 2. you should ask the user for a deposit amount, and add it to the balance.

8.If the user chooses option 3, you should ask the user for a withdrawal amount. Check to make sure there is enough money in the account and if so, subtract the withdrawal from the balance. If there isn't enough money in the account, display an error message.

9.Repeat steps 4 – 8 until the user enters menu option 4.

Technical Notes & Requirements:

1.You will need to write the main program, and finish writing the checkID method.

2.You are also required to write, and use, a method called menu. This method will not have any parameters. This method should display the menu on the screen, allow the user to make a choice, check to see if the choice is valid, and then return the choice as an integer. If the choice is invalid, the menu should display an error message and then repeat until it gets a valid choice. The menu method does NOT exit until it gets a valid choice (an integer 1-4) from the user.

3.You are required to write, and use, a method called deposit. This method will take two parameters of data type double, one being the account balance and the other being a deposit amount. This method should add the deposit amount to the balance, then return the new balance.

4.You are required to write, and use, a method called displayBalance. This method will take a single parameter of data type double, representing the account balance. This method should simply display the account balance to the screen. When printing the number to the screen, it should display a dollar sign in front of the number, and show exactly two decimal places.

5.You are required to write, and use, a method called withdraw. This method will take two parameters of data type double, one being the account balance and the other being a withdraw amount. This method should check to make sure there is enough money in the account balance to perform the withdrawal. If there isn't, the method should display an error message, then return the unchanged account balance back as a double number. If there is enough money, the method should subtract the withdrawal amount from the balance, then return the new balance as a double number.

NOTE: When the program ends, all of the changes made to the balance will be lost. When the program starts for a second time, the original balance is used again. This is because the balances are permanently coded into the checkID method. This, of course, wouldn't work for a real-world application but it suffices for the purpose of this assignment.

Explanation / Answer

PROGRAM CODE:

package util;

/*
Your name and a description
of the program go here.
*/

import java.util.*;

public class ATM {

public static Scanner kbd;

public static void main(String[] args) {

kbd = new Scanner(System.in);
String accNum, pwd, bal;
int counter = 0;
do
{
   System.out.print("Enter account number: ");
   accNum = kbd.nextLine();
   System.out.print("Enter password: ");
   pwd = kbd.nextLine();
   bal = checkID(accNum, pwd);
   counter++;
   if(bal.equals("error"))
   {
       System.out.println("Invalid credentials!");
   }
   else
       break;
}while( counter<4);
if(counter >= 4)
   System.out.println("You've reached maximum number of attempts. Good Bye!");
else
{
   double balance = Double.valueOf(bal);
   while(true)
   {
       int option = menu();
       double amount = 0.00;
       switch (option) {
              case 1: displayBalance(balance);break;
              case 2: System.out.print("Enter amount to deposit: ");
                      amount = Double.valueOf(kbd.next());
                      balance = deposit(balance, amount);
                      break;
              case 3: System.out.print("Enter amount to withdraw: ");
                              amount = Double.valueOf(kbd.next());
                              balance = withdraw(balance, amount);
                              break;
              case 4: System.exit(0);
              break;
         
          }
   }
}
kbd.close();
}

/**
* Determines if acctNum is a valid account number, and pwd is the correct
* password for the account.
* @param acctNum The account number to be checked
* @param pwd The password to be checked
* @return If the account information is valid, returns the current account
* balance, as a string. If the account information is invalid, 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";

// insert code here to determine if acctNum is a valid account number
// and pwd is the correct password for the account.
String acc_a[] = a.split(" ");
String acc_b[] = b.split(" ");
String acc_c[] = c.split(" ");
if(acctNum.equals(acc_a[0]) && pwd.equals(acc_a[1]))
   return acc_a[2];
else if(acctNum.equals(acc_b[0]) && pwd.equals(acc_b[1]))
   return acc_b[2];
else if(acctNum.equals(acc_c[0]) && pwd.equals(acc_c[1]))
   return acc_c[2];
else
return result;
}
//displaying menu on the screen and getting the selection from user
public static int menu()
{
   int option;
   System.out.println(" MENU 1. Display Balance 2. Deposit 3. Withdraw 4. Log Out");
   System.out.print("Enter your choice: ");
   option = Integer.valueOf(kbd.next());
   if(option >=1 && option<=4)
   {
       return option;
   }
   else menu();
   return -1;
}
// method to increment the balance with deposit amount
public static double deposit(double balance, double amount )
{
   return balance + amount;
}
//method to decrement the balance with withdrawal amount
public static double withdraw(double balance, double amount )
{
   if(balance < amount)
   {
       System.out.println("Insufficient balance!");
       return balance;
   }
   else
   return balance - amount;
}
//displaying balance to the user
public static void displayBalance(double balance)
{
   System.out.printf("Balance: $%.2f", balance);
}
}

OUTPUT:

Enter account number: 44567-5
Enter password: double balance = Double.valueOf(bal);
Invalid credentials!
Enter account number: 44567-5
Enter password: mypassword

MENU
1. Display Balance
2. Deposit
3. Withdraw
4. Log Out
Enter your choice: 2
Enter amount to deposit: 12

MENU
1. Display Balance
2. Deposit
3. Withdraw
4. Log Out
Enter your choice: 1
Balance: $532.36
MENU
1. Display Balance
2. Deposit
3. Withdraw
4. Log Out
Enter your choice: 3
Enter amount to withdraw: 20

MENU
1. Display Balance
2. Deposit
3. Withdraw
4. Log Out
Enter your choice: 1
Balance: $512.36
MENU
1. Display Balance
2. Deposit
3. Withdraw
4. Log Out
Enter your choice: 4

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote