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

I need help creating a basic and simple Java program. Here is the exercise. I ha

ID: 3800613 • Letter: I

Question

I need help creating a basic and simple Java program. Here is the exercise. I have included my Account class that is referred to at the bottom, below the exercise.

Use the Account class created in Programming Exercise 9.7 to 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 money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. Thus, once the system starts, it will not stop. You will need to cntrl-c to stop your program; this is ok for this assignment. If you want your program to terminate more elegantly you can add in additional logic, but this is not required.

Please refer to textbook for sample output pg. 401.

Account.java

import java.util.Date;

public class Account {

private int id;
private double balance;
static private double annualInterestRate = 0;
private Date dateCreated;

public Account() {
dateCreated = new Date();
}

public Account(int id, double balance) {
this.id = id;
this.balance = balance;
dateCreated = new Date();
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;

}

public double getBalance() {
return balance;

}

public void setBalance(double balance) {

this.balance = balance;
}

public static double getAnnualInterestRate() {
return annualInterestRate;

}

public static void setAnnualInterestRate(double annualInterestRate) {
Account.annualInterestRate = annualInterestRate;
}

public Date getDateCreated() {
return dateCreated;
}

public double getMonthlyInterestRate() {
double monthlyInterestRate = getAnnualInterestRate() / 1200;
return monthlyInterestRate;
}

public double getMonthlyInterest() {
double monthlyInterest= getBalance() * getMonthlyInterestRate();
return monthlyInterest;
}

public void withdraw(double amount) {
balance = getBalance() - amount;

}

public void deposit(double amount) {
balance = getBalance() + amount;

}


}

Explanation / Answer

//This is your Account Class
package com.ATMBanking;

import java.util.Date;

public class Account {

   private int id;
   private double balance;
   static private double annualInterestRate = 0;
   private Date dateCreated;
   public Account() {
   dateCreated = new Date();
   }
   public Account(int id, double balance) {
   this.id = id;
   this.balance = balance;
   dateCreated = new Date();
   }
   public int getId() {
   return id;
   }
   public void setId(int id) {
   this.id = id;
   }
   public double getBalance() {
   return balance;
   }
   public void setBalance(double balance) {
   this.balance = balance;
   }
   public static double getAnnualInterestRate() {
   return annualInterestRate;
   }
   public static void setAnnualInterestRate(double annualInterestRate) {
   Account.annualInterestRate = annualInterestRate;
   }
   public Date getDateCreated() {
   return dateCreated;
   }
   public double getMonthlyInterestRate() {
   double monthlyInterestRate = getAnnualInterestRate() / 1200;
   return monthlyInterestRate;
   }
   public double getMonthlyInterest() {
   double monthlyInterest= getBalance() * getMonthlyInterestRate();
   return monthlyInterest;
   }
   public void withdraw(double amount) {
   balance = getBalance() - amount;
   }
   public void deposit(double amount) {
   balance = getBalance() + amount;
   }
}

//This is your UserTest Class
package com.ATMBanking;

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

import javax.swing.text.html.HTMLDocument.Iterator;

public class UserTest {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

      
       ArrayList<Account> al=new ArrayList<Account>();
      
      
       Account a1= new Account(1,100);
       Account a2= new Account(2,100);
       Account a3= new Account(3,100);
       Account a4= new Account(4,100);
       Account a5= new Account(5,100);
       Account a6= new Account(6,100);
       Account a7= new Account(7,100);
       Account a8= new Account(8,100);
       Account a9= new Account(9,100);
       Account a10= new Account(10,100);
       al.add(a1);
       al.add(a2);
       al.add(a3);
       al.add(a4);
       al.add(a5);
       al.add(a6);
       al.add(a7);
       al.add(a8);
       al.add(a9);
       al.add(a10);
       //Account a=null;
      
       while(true){
           Scanner sc=new Scanner(System.in);
           System.out.print(" Enter Account no.:");
           int acc = sc.nextInt();
           int val;
           Account aa;
      
                  
           if(acc<=10){
               System.out.println(" Account Operations ");
       System.out.println("Enter 1 for viewing the current balance");
       System.out.println("Enter 2 for withdrawing money");
       System.out.println("Enter 3 for depositing money");
       System.out.println("Enter 4 to Exit");
               //System.out.print("Enter your choice [1,2,3 & 4]: ");
               while(true){
                   int amount;
                  
                   System.out.print(" Enter your choice [1,2,3 & 4]: ");
          
           int choice = sc.nextInt();
           switch (choice)
           {
           case 1 :
               aa=al.get(acc);
                           System.out.print("Your Balance is: "+aa.getBalance());;
           break;
           case 2 :
               System.out.print("Enter the withdraw Amount: ");
                           amount =sc.nextInt();
                           aa=al.get(acc);
                           aa.withdraw(amount);
                          
           break;
             
           case 3 :
               System.out.print("Enter the Deposite Amount: ");
                           amount =sc.nextInt();
                           aa=al.get(acc);
                           aa.deposit(amount);;
               /*for(Student stu:al){
                   stu.getDisplay();
               }
               */
           break;
             
           case 4 :
               //System.out.println("Bye....THANK YOU");
           //System.exit(0);
             
           break;
          
           default :
           System.out.println("Wrong Entry ");
           break;   
           }
           if(choice==4){
               System.out.println("Bye....THANK YOU");
               break;
           }//break;
               }
              
           }else{
               System.out.println("Please enter valid Account number");
           }
          
          
       }
   }

}

Output:


Enter Account no.:1

Account Operations

Enter 1 for viewing the current balance
Enter 2 for withdrawing money
Enter 3 for depositing money
Enter 4 to Exit

Enter your choice [1,2,3 & 4]: 1
Your Balance is: 100.0
Enter your choice [1,2,3 & 4]: 3
Enter the Deposite Amount: 400

Enter your choice [1,2,3 & 4]: 1
Your Balance is: 500.0
Enter your choice [1,2,3 & 4]: 4
Bye....THANK YOU

Enter Account no.:2

Account Operations

Enter 1 for viewing the current balance
Enter 2 for withdrawing money
Enter 3 for depositing money
Enter 4 to Exit

Enter your choice [1,2,3 & 4]: 1
Your Balance is: 100.0
Enter your choice [1,2,3 & 4]: 3
Enter the Deposite Amount: 300

Enter your choice [1,2,3 & 4]: 4
Bye....THANK YOU

Enter Account no.:1

Account Operations

Enter 1 for viewing the current balance
Enter 2 for withdrawing money
Enter 3 for depositing money
Enter 4 to Exit

Enter your choice [1,2,3 & 4]: 1
Your Balance is: 500.0
Enter your choice [1,2,3 & 4]: 2
Enter the withdraw Amount: 200

Enter your choice [1,2,3 & 4]: 1
Your Balance is: 300.0
Enter your choice [1,2,3 & 4]: 4
Bye....THANK YOU

Enter Account no.:11
Please enter valid Account number

Enter Account no.:

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