In this assignment you'll be implementing a simple ATM.

You'll be writing two classes:

  • Account - Objects of this class represent a customer's bank account
  • ATM - This class creates two objects of the Account class and provides a menu to perform transactions, similar to an automated teller machine. This class contains the main method.

Account Class

The Account class keeps track of customer information like their name and bank balance, and can perform transactions like depositing or withdrawing money from the account. The Account class should have the following fields (attributes):

  • customerName - The name of the customer as a string
  • id - The customer ID number (int)
  • balance - The account balance (double)
  • annualInterestRate - Percent interest the account earns per year (double)

The Account class should have the following methods:

  • A two-argument constructor that creates a bank account with specified ID number and customer name
  • Accessor methods (getters) for all fields
  • Mutator methods (setters) for all fields
  • A one-argument method named deposit that deposits the specified amount to the account (adds to the balance)
  • A one-argument method named withdraw that withdraws the specified amount from the account (subtracts from the balance)
  • A no-argument method named monthlyInterest that calculates and returns the interest earned this month ($). For example, if the account balance is $1000 and the annual interest rate is 3% then the interest earned in a month is $2.50. Here is how you can calculate this: balance * (annualInterestRate / 12 / 100) You need to divide by 12 because the interest rate is annual but the interest amount is for one month. You need to divide by 100 because the interest rate is a percent.

ATM Class

This class implements a console user interface for the ATM. It should do the following:

1. In the main method, create two bank accounts (two Account objects). The first account should be created with ID 101 and your name. The second account should be created with ID 102 and the name of your favorite movie actor.

2. Set the balance for account ID 101 to $50 and account ID 102 to $1000. Set the annual interest rate for both accounts to 5%.

3. Prompt the user to enter an ID. This is the ID of the account to use in the next step. The only valid answers here will be the IDs used in step 1. If the ID is entered incorrectly then print an error message and ask for the ID again.

4. In another method of the ATM class, display the main menu. This method is called from main and should be named 'menu'. The menu method allows you to perform transactions like deposit, withdraw, and check account info. You will pass one of the two account objects to the menu method (pass the account the user selected). You should declare the menu method like this:

public void menu(Account acct)

Notice that this method accepts one parameter, the account object the user selected by entering an ID number in step 3.

Study the sample run below to see what the menu might look like and what each function should do. The "Account info" function should display the customer name, the customer's bank balance, and the monthly interest amount.

Enter an account ID: 102

Main Menu
1: Account info
2: Withdraw
3: Deposit
4: Exit
Please choose what you’d like to do: 1

Customer: Clint Eastwood
Account Balance: $1000.00
Monthly interest earned: $4.17

Main Menu
1: Account info
2: Withdraw
3: Deposit
4: Exit
Please choose what you’d like to do: 3

Enter the amount to deposit: 3.50

Main Menu
1: Account info
2: Withdraw
3: Deposit
4: Exit
Please choose what you’d like to do: 2

Enter the amount to withdraw: 10

Main Menu
1: Account info
2: Withdraw
3: Deposit
4: Exit
Please choose what you’d like to do: 1

Customer: Clint Eastwood
Account Balance: $993.50
Monthly interest earned: $4.14

Main Menu
1: Account info
2: Withdraw
3: Deposit
4: Exit
Please choose what you’d like to do: 4

Enter an account ID:

Notes

The menu method should display the main menu again and ask for another choice after every transaction (1, 2, 3), except exit (4). When exit is selected it should return to the main method, which prompts for another account ID. Thus once the system starts it will not stop (this is like a real ATM where a regular user can't stop the system).

For full marks do not use the keyword 'static' except for the main method declaration and for constant (final) fields. Youll need to create an object of the ATM class in the main method so you can call the menu method.

Date of Creation

Add a field to the account class, as follows:

dateCreated - A field of type Date which stores the date/time the account was created (Date is in the java.util package, see Java documentation)

You should write a getter for the dateCreated field, but not a setter. When an object of type Date is created using the default constructor it gets initialized to the current time, you can use this to automatically initialize the field.

Update your ATM "account info" menu option so that it also prints out the date/time the account was created.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.