Array of Objects Use the Account class created in Question 5 of Assignment 2 to simulate an ATM machine (name the class as ATMWithAccount). Create ten accounts in an array with id 1, 2, ..., 10, and initial balance $100. The array index for each account is the same as the account id. (Hint: This indicates that the array size is 11.) Set the first array element as null. 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. Once you enter id 0, the program prints out a summary of the ten accounts, including the id and the balance. Then the program is terminated. All floating-point numbers should be printed out with 2 decimal places. A sample run is as follows: Enter an account id (1-10): 11 Invalid id Enter an account id (1-10): 4 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 1 The balance is 100.00 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 4 You exit this account Enter an account id (1-10): 5 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 2 Enter an amount to withdraw: 200 Your balance is not enough. Main menu 1: check balance 2: withdraw Enter an account id (1-10): 8 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 3 Enter an amount to deposit: 500 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 4 You exit this account Enter an account id (1-10): 0 Here is a summary of your accounts: Account 1: balance is 100.00 Account 2: balance is 100.00 3: deposit 4: exit Enter a choice: 2 Enter an amount to withdraw: 30 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 4 You exit this account Account 3: balance is 100.00 Account 4: balance is 100.00 Account 5: balance is 70.00 Account 6: balance is 100.00 Account 7: balance is 100.00 Account 8: balance is 600.00 Account 9: balance is 100.00 Account 10: balance is 100.00 You exit the ATM

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write the code in java and please dont plagarise or copy from other sources and read the question carefully. In the question it says assignment 2 question 5 account class code. Here is the code: 

import java.util.Date;
 
public class Account
{
  private int id;
  private double balance;
  private static double annualInterestRate = 0.012;
  private Date dateCreated;
 
  public Account ()
  {
this (0, 0);
  }
 
  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 static double getAnnualInterestRate ()
  {
return annualInterestRate;
  }
 
  public static void setAnnualInterestRate (double annualInterestRate)
  {
Account.annualInterestRate = annualInterestRate;
  }
 
  public Date getDateCreated ()
  {
return dateCreated;
  }
 
  public double getMonthlyInterestRate ()
  {
return annualInterestRate / 12;
  }
 
  public double getMonthlyInterest ()
  {
return balance * getMonthlyInterestRate ();
  }
 
  public void withdraw (double amount)
  {
balance -= amount;
  }
 
  public void deposit (double amount)
  {
balance += amount;
  }
}

 

1.
Array of Objects
...
Use the Account class created in Question 5 of Assignment 2 to simulate an ATM machine (name the
class as ATMWithAccount). Create ten accounts in an array with id 1, 2,
10, and initial balance
$100. The array index for each account is the same as the account id. (Hint: This indicates that the array
size is 11.) Set the first array element as null. 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. Once you enter id 0, the program prints out a summary of the ten accounts, including
the id and the balance. Then the program is terminated. All floating-point numbers should be printed out
with 2 decimal places. A sample run is as follows:
Enter an account id (1-10): 11
Invalid id
Enter an account id (1-10): 4
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1
The balance is 100.00
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 4
You exit this account
Enter an account id (1-10): 5
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 2
Enter an amount to withdraw: 200
Your balance is not enough.
Main menu
1: check balance
2: withdraw
3: deposit
Enter an account id (1-10): 8
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 3
Enter an amount to deposit: 500
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 4
You exit this account
Enter an account id (1-10): 0
Here is a summary of your accounts:
Account 1: balance is 100.00
Account 2: balance is 100.00
4: exit
Enter a choice: 2
Enter an amount to withdraw: 30
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 4
You exit this account
Account 3: balance is 100.00
Account 4: balance is 100.00
Account 5: balance is 70.00
Account 6: balance is 100.00
Account 7: balance is 100.00
Account 8: balance is 600.00
Account 9: balance is 100.00
Account 10: balance is 100.00
You exit the ATM
Transcribed Image Text:1. Array of Objects ... Use the Account class created in Question 5 of Assignment 2 to simulate an ATM machine (name the class as ATMWithAccount). Create ten accounts in an array with id 1, 2, 10, and initial balance $100. The array index for each account is the same as the account id. (Hint: This indicates that the array size is 11.) Set the first array element as null. 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. Once you enter id 0, the program prints out a summary of the ten accounts, including the id and the balance. Then the program is terminated. All floating-point numbers should be printed out with 2 decimal places. A sample run is as follows: Enter an account id (1-10): 11 Invalid id Enter an account id (1-10): 4 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 1 The balance is 100.00 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 4 You exit this account Enter an account id (1-10): 5 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 2 Enter an amount to withdraw: 200 Your balance is not enough. Main menu 1: check balance 2: withdraw 3: deposit Enter an account id (1-10): 8 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 3 Enter an amount to deposit: 500 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 4 You exit this account Enter an account id (1-10): 0 Here is a summary of your accounts: Account 1: balance is 100.00 Account 2: balance is 100.00 4: exit Enter a choice: 2 Enter an amount to withdraw: 30 Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 4 You exit this account Account 3: balance is 100.00 Account 4: balance is 100.00 Account 5: balance is 70.00 Account 6: balance is 100.00 Account 7: balance is 100.00 Account 8: balance is 600.00 Account 9: balance is 100.00 Account 10: balance is 100.00 You exit the ATM
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education