4 38 C2 Tue Nov 29 1 14 12 PM E Chrome File Edit View Histor

4 38% C2 Tue Nov 29 1 14 12 PM E Chrome File Edit View History Bookmarks People Window Help c chegg study l Guided solutio x Lab10 Programming Princ x Josh https://kennesaw.view.usg.ed lle/conten 1103674 u/d2 Apps Bookmarks YouTube home Apple N DestinyLFG.Net IT Dm Destiny Tracker De D Microsoft word ja... c ntro To Java Prog 10.7 (Game: ATM machine) Use the Account class created in Programming Exer- cise 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.

Solution

// Account.java

import java.util.Date;

public class Account{
   private int id;
   private double balance;
   private double annualInterestRate;
   private Date dateCreated;
   public Account() {
       id = 0;
       balance = 0;
       annualInterestRate = 0;
       dateCreated = new Date();
   }
   public Account(int id, double balance) {
       this.id = id;
       this.balance = balance;
       this.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 double getAnnualInterestRate() {
       return annualInterestRate;
   }
   public void setAnnualInterestRate(double annualInterestRate) {
       this.annualInterestRate = annualInterestRate;
   }
   public Date getDateCreated() {
       return dateCreated;
   }
   public double getMonthlyInterestRate(){
       return annualInterestRate / 12.0;
   }
   public double getMonthlyInterest(){
       return this.getMonthlyInterestRate() * balance / 100.0;
   }
   public void withdraw(double amount){
       if(balance > amount) balance -= amount;
       else System.out.println(\"Insufficient balance!\");
   }
   public void deposit(double amount){
       balance += amount;
   }
}

// Test.java

public class Test{
   public static void main(String args[]){
       Account object = new Account(1122, 20000);
       object.setAnnualInterestRate(4.5);
       object.withdraw(2500);
       object.deposit(3000);
       System.out.println(\"Balance: \" + object.getBalance() + \"\ Monthly interest: \" + object.getMonthlyInterest() + \"\ Date of creation: \" + object.getDateCreated());
   }
}

 4 38% C2 Tue Nov 29 1 14 12 PM E Chrome File Edit View History Bookmarks People Window Help c chegg study l Guided solutio x Lab10 Programming Princ x Josh htt
 4 38% C2 Tue Nov 29 1 14 12 PM E Chrome File Edit View History Bookmarks People Window Help c chegg study l Guided solutio x Lab10 Programming Princ x Josh htt

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site