Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this homework please! Overview In this assignment you will write a program that will model a bank with multiple patrons who each

Need help with this homework please!

Overview

In this assignment you will write a program that will model a bank with multiple patrons who each have multiple accounts. The user will be able to add and remove patrons, as wellas have the individual patrons manage their account and money. This will involve interactions between multiple classes which you have defined. When working as a programmer, you are often not writing code from scratch, but are instead adding to an existing project using classes written by others. With this in mind, you will not only be defining two of your own classes, but will also be using a class which will be provided to you. Note: The requirements listed below are provided in a specific order. Due to the way methods depend on other methods and classes depend on other classes, the requirements are provided in a bottom-up approach so that everything is defined before you try and use it. You are welcome to tackle the steps in any order, but you are likely to have issues due to not having methods defined that you need in order to write other ones. This bottom up approach is often how code is written. However, the downside of this approach is that your main method will be the last thing you write. Make sure you make use of your empty main method to test methods and classes youve written before moving too much further ahead. The worst mistake to make would be to write all of this out before trying to test it at all!

Requirements

Your program must do the following in order to receive full credit on this assignment.

1. Download the AccountType enum java file, which is attached to the assignment on Blackboard. Add it to your project and ensure it compiles. a. Sometimes an IDE, namely Eclipse, will have issues using files you did not create. If you get several problems (or see a message asking you to Select Ant build when you go to run it) create your own file and copy and paste the contents into it.

2. Download the BankAccount class and add it to your project as well. a. You are not to make any sort of edits to either of these files!

3. Create a new class called BankPatron.

4. Give BankPatron the following private instance variables. a. First Name b. Last Name c. Salary d. Cash on Hand e. Two BankAccount objects i. It is up to you to determine the needed types for all of these. Look at how BankAccount handles its variables relating to money. You should use the same type it does.

5. Create a default constructor, and then a regular constructor which takes the following parameters. a. First Name b. Last Name c. Salary d. Cash on Hand i. Both constructors will initialize, but not create objects for, the two accounts.

6. Write a get method that returns the full name of the patron. a. Be sure to put a space between the first and last names.

7. Write a get for salary and cash on hand.

8. Write a void method that gives the patron a pay check. a. That is, calculate the amount one pay check would be and add it to their cash on hand. b. Assume that the salary is yearly, they work all weeks of the year, and are paid bi-weekly. i. As in they are paid every two weeks.

9. Write a method that gets the specified BankAccount. a. It takes an int parameter of 1 or 2 that represents the first or second of the two accounts this patron has. b. If the number is invalid or they do not have that account yet the method should return null.

10. Write a boolean method to make a deposit which takes a double for the amount to deposit and an account to put the money in. a. The provided amount is only added to the account if the patron has at least that much cash on hand. i. That much is then taken from their cash on hand. b. The method should return true if the money was successfully deposited, otherwise it will return false.

11. Write a boolean method which has parameters for an amount and an account to withdraw the money from. a. The method should only return true if the money was successfully withdrawn. i. Use BankAccounts built in withdraw method. b. The money is added to the patrons cash on hand.

12. Write a boolean method that adds an account to the patron. a. It should have a parameter for rate and one for the account type. b. This account becomes the patrons first account if they dont already have one, or their second if they already have a single account. c. If they already have two accounts the method returns false, otherwise it returns true.

13. Write a boolean method to remove one of the two accounts from this patron. a. Like getAccount, take an int to determine which account to remove. b. Return true only if the account was removed. i. If the account was already null, it would return false. c. Note: This concludes the BankPatron class.

14. Create a new PatronList class which has five private patron instance variables.

15. Create a default constructor which sets all the patrons to null. a. Do not create another constructor.

16. Create an int method that returns an int representing the first null patron. a. This would be 0 for the first patron, 1 for the second, etc. b. This number represents the slot a new patron could be added to. c. Return -1 if there are no empty slots.

17. Create a boolean method which takes a BankPatron and adds them as a new patron. a. They can only be added if there is a null instance patron. i. Otherwise the line at the bank is full and this method returns false.

18. Overload the method from the previous step to accept a first and last name, a salary, and cash on hand for a patron and create and add this new patron to the bank. a. This method can be only a single line long!

19. Write a method that returns the patron specified in the int parameter. a. Again, 0 represents the first patron and so on. b. Returns null if the parameter is invalid or no patron exists in that slot.

20. Write a method that accepts a patrons full name as a parameter and returns that patron. a. Return null if the patron is not found.

21. Write a boolean method that removes the patron provided in the parameter from the bank.

22. Write a string method to build and return a string of the patrons info which can be printed later. a. It should print their full name first. b. It then prints their first account info. i. This takes the form: (accountType) (accountNumber) Balance: (balance) Interest Rate: (rate). ii. See example outputs. iii. This is assuming they have an account at all. c. Then print their second account in the same format, if they have one. i. If they dont have any accounts only their name should be printed. d. Note: This concludes the PatronList class.

23. In your main file, create a Scanner and a PatronList object that will be useable by all methods in the class.

24. Create a main menu method that will print out the menu, accept input from the user, validate that input, and return the users choice. The main menu choices are as follows. a. List Patrons b. Add New Patron c. Remove Patron d. Patron Specific Actions e. Quit

25. Create a patron menu method that will work like the main menu, but prints out the menu for actions for a specific patron when the user chooses option d in the main menu. a. Add New Account b. Close Account c. Get Paid d. Apply Interest to Accounts e. Make Deposit f. Make Withdraw g. Return to Main Menu

26. Create a third menu method that prompts the user for which account type they want. This will be used when adding new accounts to a patron. a. Checking b. Savings c. CD d. Money Market e. IRA

27. Write a void method that handles actions for the patron specific menu. a. This should take a patron object as a parameter and apply all actions to that patron. b. Call the method to print the patron specific menu and store the user input. c. Create a loop that will run until the user chooses to return to the main menu. i. As always dont forget to reprint the menu and take a new input at the bottom of the loop. d. The actions to take in the loop are described in the following steps.

28. If the user chose to add a new account, determine what account type the user wants, accept a double as the interest rate from the user and then use that information to add a new account to the patron. a. Print out a message depending on whether adding the account succeeded or failed.

29. If the user chose to remove an account, accept an int from the user representing which account to remove and remove that from the patron object. a. Again, print a success or failure message.

30. If the user chose to have the patron receive a paycheck, call the method you wrote to have the patron get a paycheck. 31. If the user chose to apply the interest rate to the accounts, then calculate the amount of interest for each of the Patrons accounts and add it to the balance of that account. a. For example, if the first account had $100 in it and had a 2% interest rate, it would have $102 in it afterwards. b. Note that the rates are different for the two accounts and each should only get its own rate amount added to it. c. Obviously, the accounts must exist in order to have interest added to them.

32. If the user chose to make a deposit, have the user specify which account to make a deposit in, using an in value again, then accept the amount to deposit, and finally have the patron make that deposit. a. Print a success or failure message. b. If the specified account does not exist, print an error message instead.

33. If the user chose to make a withdrawal, follow the same procedure as making a deposit, but withdraw the money instead. a. Again print the appropriate messages.

34. Finally, write your main method. a. Print a welcome message. b. Call your main menu method to show the menu and get the users choice. c. Have a loop that will run until the user chooses to exit. i. The steps to do in the loop are specified in the next steps. d. Print a goodbye message after the loop before the program ends.

35. If the user chose to list the patrons, print out the information for each patron in the PatronList. a. If there are none, print None. b. Use the method you defined in PatronList to get a string of each patrons information.

36. If the user chose to add a new patron, get the appropriate information and add the patron to the bank. a. You will need the first and last name of the patron, their salary, and how much cash they have on hand. b. Print a message welcoming them to the bank if they were successfully added to the PatronList, otherwise print a message that the bank line is full already.

37. If the user chose to remove a patron, get the patrons name and remove them from the PatronList. a. Take the patrons full name from the user. b. Use the method you defined in PatronList to get that patron. c. If the patron doesnt exist, print a message that theres no one by that name.

38. If the user choise to do patron specific actions, get the patrons name and pass that patron to the patron specific method you created previously. a. Again, get their full name and use the method you already wrote to get that patron. b. If the patron doesnt exist, print an error instead of moving to the patron specific menu.

/* * You are not to edit this file. You should look through it, but * the graders will be using an exact copy of this file and if * you make changes it will stop your program from working * (or even compiling) and cost you a lot of points. */ public class BankAccount { private int accountNumber; private double balance; private double interestRate; private String holderFirstName; private String holderLastName; private AccountType type; private static int nextAccountNum = 1001; public BankAccount() { accountNumber = getNextAccountNum(); balance = 0.0; interestRate = 0.0; holderFirstName = ""; holderLastName = ""; type = AccountType.Checking; } public BankAccount(String first, String last, double rate, AccountType at) { accountNumber = getNextAccountNum(); balance = 0.0; interestRate = rate; holderFirstName = first; holderLastName = last; type = at; } private int getNextAccountNum() { return nextAccountNum++; } public int getAccountNum() { return accountNumber; } public double checkBalance() { return balance; } public void deposit(double amount) { balance += amount; } public boolean withdraw(double amount) { boolean success = true; if((balance - amount) >= 0.0) // Only able to withdraw if there is actually enough money. { balance -= amount; } else { success = false; } return success; } public double getRate() { return interestRate; } public void setRate(double rate) { interestRate = rate; } public void applyInterest() { balance += (balance * (interestRate / 100)); } public String getHolderFullName() { return holderFirstName + " " + holderLastName; } public AccountType getType() { return type; } } 
// Do NOT edit this file! public enum AccountType {Checking, Savings, CD, MoneyMarket, IRA} 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Neo4j Data Modeling

Authors: Steve Hoberman ,David Fauth

1st Edition

1634621913, 978-1634621915

More Books

Students also viewed these Databases questions

Question

Conduct a needs assessment. page 269

Answered: 1 week ago