Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with an assignment. My instructor is extremely hard to understand and has given us our most difficult assignment yet. We are simulating

I need help with an assignment. My instructor is extremely hard to understand and has given us our most difficult assignment yet. We are simulating a bank account in which we give the user multiple options on a menu and let them choose which actions they want to take. We are given two sample codes that are needed to complete the assignment, they are as follows:

BankAccount:

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; } } 

The second one is AccountType.

public enum AccountType {Checking, Savings, CD, MoneyMarket, IRA}

This is what our program has to do:

3. Create a new class called BankPatron. 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.

1. 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. Assume that the salary is yearly, they work all weeks of the year, and are paid bi-weekly.

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. 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.

Example Inputs:

#1

Welcome to the Bank!

a. List Patrons b. Add New Patron c. Remove Patron

d. Patron Specific Actions e. Quit a Patrons currently at the bank: None

a. List Patrons b. Add New Patron c. Remove Patron d. Patron Specific Actions e. Quit b What is the first name of the new patron? Tyler Their last name?

Baron Their yearly salary? 100000 // I wish How much cash do they have on hand? 100 Welcome to the bank, Tyler a. List Patrons b. Add New Patron c. Remove Patron d. Patron Specific Actions e. Quit a Patrons currently at the bank: Tyler Baron a. List Patrons b. Add New Patron c. Remove Patron d. Patron Specific Actions e. Quit e Thank you for coming.

#2

Welcome to the Bank!

a. List Patrons b. Add New Patron c. Remove Patron

d. Patron Specific Actions e. Quit c Type the full name of the patron you want. Amber Bennett

There is no patron by that name. a. List Patrons b. Add New Patron c. Remove Patron

d. Patron Specific Actions

e. Quit b What is the first name of the new patron? Mohammed Their last name? Albasha Their yearly salary? 50000 How much cash do they have on hand? 100 Welcome to the bank, Mohammed a. List Patrons b. Add New Patron c. Remove Patron d. Patron Specific Actions e. Quit c Type the full name of the patron you want. Mohammed Albasha Mohammed Albasha left the bank. a. List Patrons b. Add New Patron c. Remove Patron d. Patron Specific Actions e. Quit a Patrons currently at the bank: None a. List Patrons b. Add New Patron c. Remove Patron d. Patron Specific Actions e. Quit e Thank you for coming.

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

Students also viewed these Databases questions

Question

3. Evaluate your listeners and tailor your speech to them

Answered: 1 week ago