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

(Objects and classes) Write a Java program for ATM machines to meet the followin

ID: 3820041 • Letter: #

Question

(Objects and classes) Write a Java program for ATM machines to meet the following requirements:

1. Define an Account class with the following 4 private data fields:

• An int data field named id for the Account user account id (default 0).

• A String data field named name for the Account user name (default “NA”).

• A double data field named balance for the Account (default 0).

• A Date data field named dateCreated that stores the date when the Account was created.

2. Implement the following methods for the Account class:

• A constructor with 3 parameters ( id, name, balance ) – assign the parameter values to these 3 data

fields and initialize dateCreate= new Date();

• The accessor and mutator methods for balance.

• The accessor method for id, name, dateCreated.

• A method named withdraw that withdraws a specified amount from the Account.

• A method named deposit that deposits a specified amount to the Account.

• A method named printReceipt() that will print the 1) AccountID, 2)Account name, 3) the date

Account was created, and 4) current balance.

3. Write a test program that

• Creates three Account users with initial values as below:

id: assign 1 to the first user, assign 2 to the 2nd user, assign 3 to the 3rd user.

name: you need to assign different name for each user

balance: every user has the same initial amount 2000.

• Call deposit and withdraw methods for every user. The first user deposits 500. The 2nd user withdraws

600. The 3rd user deposit 200 and withdraw 400.

• Call the printReceipt() to display the account information for each user.

• Find the person who has the highest balance after all transactions and show the account name and

balance.

• This project should be coded in ONE java file.

Explanation / Answer

import java.util.Date;


public class ATMTest {

   public static void main(String[] args) {
       Account user1 = new Account(1,"Loknath User1",2000.0d);
       Account user2 = new Account(2,"Harish User2",2000.0d);
       Account user3 = new Account(3,"Ravi User1",2000.0d);
       user1.deposit(500.0d);
       user2.withdraw(600.0d);
       user3.deposit(200.0d);
       user3.withdraw(400.0d);
       user1.printReceipt();
       user2.printReceipt();
       user3.printReceipt();
      
       System.out.println("Highest Balance :"+user1.getName()+" :"+user1.getBalance());
      
   }

}
class Account{
   private int id;
   private String name;
   private double balance;
   private Date dateCreated;
   public Account(int id,String name,double balance){
       this.id = id;
       this.name = name;
       this.balance = balance;
       this.dateCreated = new Date();
   }
   public void withdraw(double amt){
       if(balance>=amt)
           balance -= amt;
       else{
           System.out.println("Don't have suficient balance");
       }
   }
   public void deposit(double amt){
       balance+=amt;
   }
   public void printReceipt(){
       System.out.println("====================>RECEIPT<=================== ");
       System.out.println("Account ID : "+id);
       System.out.println("Account Name : "+name);
       System.out.println("The Date Account was created : "+dateCreated);
       System.out.println("Current Balance : "+balance);
       System.out.println("-------------------------------------------------");
      
   }
   public int getId() {
       return id;
   }
   public void setId(int id) {
       this.id = id;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public double getBalance() {
       return balance;
   }
   public void setBalance(double balance) {
       this.balance = balance;
   }
   public Date getDateCreated() {
       return dateCreated;
   }
   public void setDateCreated(Date date) {
       this.dateCreated = date;
   }
  
}