Question
Homework 1 4 Points Instructions: This homework models after a banking situation with ATM machine. You are required to create three classes, Account, Transaction, and
Homework 1 4 Points Instructions: This homework models after a banking situation with ATM machine. You are required to create three classes, Account, Transaction, and the main class (with the main method). Please closely follow the requirements below. Requirements for the Transaction class: A private Date data field that stores the date of the transaction A private char data field for the type of the transaction, such as W for withdrawal and D for deposit A private double data field for the amount of the transaction A private double data field for the balance of the account after the transaction A private String data field for the description of the transaction A constructor that creates an instance of the Transaction class with specified values of transaction type, amount, balance, and description, and date of the transaction. Note: Instead of passing a Date object to the constructor, you should use the new operator inside the body of the constructor to pass a new Date instance to the date data field. Define the corresponding accessor (get) methods to access a transactions date, type, amount, description, and balance, i.e., you need to define 5 get methods. Define a toString() method which does not receive parameters but returns a String that summarizes the transaction details, including transaction type, amount, balance after transaction, description of the transaction, and transaction date. You can organize and format the returned String in your own way, but you must include all of the required information. Note: the purpose of the Transaction class is to document a banking transaction, i.e., when a transaction happens, you can use the transaction parameters to create an instance of the Transaction class. Requirements for the Account class: A private int data field for the id of the account. A private String data field for the name of the customer. A private double data field for the balance of the account. A private double data field for the annual interest rate. Key assumptions: (1) all accounts created following this class construct share the same interest rate. (2) While the annual interest rate is a percentage, e. g., 4.5%, users will just enter the double number as 4.5 (instead of 0.045) for simplicity. Therefore, you, the developer, need to divide the annual interest rate by 100 whenever you use it in a calculation. A private Date data field that stores the account creating date. A private ArrayList data field that stores a list of transactions for the account. Each element of this ArrayList must be an instance of the Transaction class defined above. A no-arg constructor that creates a default account with default variable values. A constructor that creates an instance of the Account class with a specified id and initial balance. A constructor that creates an instance of the Account class with a specified id, name, and initial balance. Note: for all constructors, instead of passing a Date object to the constructor, you should use the new operator inside the body of the constructor to pass a new Date instance to the date data field. Define corresponding accessor (get) and mutator (set) methods to access and reset the account id, balance, and interest rate, i.e., you need to define 3 get methods and 3 set methods. Define corresponding accessor (get) methods to access the account name, transactions, and date created information, i.e., you need to define 3 get methods Define a method named getMonthlyInterest() that returns the monthly interest earned. Define a method named withdraw, which (1) withdraws a specified amount for a specified purpose from the account; (2) creates an instance of the Transaction class to represent this withdraw transaction; and (3) adds this transaction including its description to the ArrayList data field of the class. Define a method named deposit, which (1) deposits a specified amount from a specified source to the account; (2) creates an instance of the Transaction class to represent this deposit transaction; and (3) adds this transaction including its description to the ArrayList data field of the class. Notes: (1) The method getMonthlyInterest() is to return monthly interest earned, not the interest rate. Monthly interest = balance * monthlyInterestRate, where monthlyInterestRate = annualInterestRate/12. (2) The constructors for the Account class will initiate the date data field. (3) You should create the Account and Transaction classes as independent files in the same package of your main class. Requirements for the main class: To test the two classes above, in the main method of your main class you first need to do the following: Create an instance of the Account class with an annual interest rate of 1.5%, a balance of 1000, an id of 1122, and a name as George. Deposit $3000 as salary to the account and then withdraw $2500 as rent from the account. Print an account summary that shows the account holders name, annual interest rate, balance, monthly interest, the date when this account was created, and all transactions. (Check the results of this print statement to verify that your Account and Transaction classes work properly.) After you pass the above test, continue to do the rest. Next, in the main method, create an Array of ten accounts with account IDs as 1, 2, . . ., 10, and an initial balance of $100 for each account. You will use this Array to simulate an ATM machine experience in the main method. Simulate an ATM machine experience: The ATM system will first prompt the user to enter an ID (corresponding to user login), and it will verify if the ID is a valid one. An ID is valid if it matches to one of the accounts in the 10-account Array. If the ID is valid, the system will present the user an ATM main menu. Otherwise, the system will ask the user to enter a correct ID. That is, the system will not present the ATM main menu until the user enters a correct ID. Description of the ATM machine main menu: This ATM machine main menu offers users four choices: choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu (corresponding to user logoff). The ATM main menu prompts the user to enter a choice, and depending on the users choice it may ask for additional input (i.e., withdraw or deposit amount and purpose) before acting on the users choice. Your code should behave properly for each user choice, demonstrated in the sample-run figure at the end. Description of the sample-run figure (shown at the end): In the sample-run figure below, the user first entered choice 1 for viewing the current balance, and after hitting the Enter key a statement of balance was shown. Then the user entered 2 for withdrawing money, and after hitting the Enter key the system asked the user to enter the withdraw amount. The user next entered 1 to verify the balance amount. Afterward, the user entered 3 for depositing money, and after hitting the Enter key the system asked the user to enter the deposit amount. Again, the user next entered 1 to verify the balance amount. Lastly, the user entered 4 for exiting the main menu and the system responded by prompting for an id again. Note: As a modification of the sample-run figure, you should let user enter a withdraw or deposit description for choices 2 and 3. Additional simulation requirements: You may have noticed that based on the above ATM simulation description, once the system starts it will not stop because after a user chooses option 4 to exit, the ATM system will be ready for the next user by asking user to enter an ID again. To give users an option of exiting the system after a few test rounds of ATM simulation, inform users that when entering an ID, enter 0 to exit the ATM run (since valid ids are from 1 to 10). That is, if users enter 0 as ID, instead of showing the main menu, the system will print out all ATM transactions for each account (in the Array) that has incurred transactions and then terminate the project. Suggestions: The objective of this HW is to model an ATM machine experience described above, and there are many design options to choose from. You should define a few variables and create a Scanner to capture the users inputs. You should also define a few methods in the main class, to be used inside the main method, to make the main method looks lean. (1) Use a method to display the main ATM menu, capture and return a valid user choice. (2) In another method, use either multiple if-else or switch statements to process user choice. Consider creating atmWithdraw and atmDeposit methods to further simplify the code. (3) Use an appropriate loop control to prompt users to enter an ID, and only after receiving a valid ID (matching to one of the accounts in the 10-element array) will the system display the main ATM menu and process users choices until the user chooses to exit the ATM main menu. (4) After completing all the requirements, test your code through a few sample runs and verify the printed results.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started