Create a project, and in it a class with a main.
Part A
☑ Add a class Account, which has an instance variable for a balance☑ Add a toString that returns either something like
$4583.02
At this point, go into your main and create an Account object. Set its balance and make sure that when you print it you see the right result.
☑ To Account, add a method deposit which takes a double and adds it to the balance.
Remember that "takes" always means a method has a parameter. This method is changing the value of the balance, but we don't have to pass the balance as a parameter since it is an instance variable. Since I didn't say what type it returns, it is probably void.
In main, try calling your deposit method for the Account and then printing the Account again to see that its balance changes correctly.
☑ In Account, add a method withdraw which takes a double and subtracts it from the balance. If the amount is larger than the balance, set the balance to 0. Either way, return however much money we were actually able to withdraw.
Since this method returns something, it will not be void. It needs to return a value in every case.
Again, go into main, and this time try withdrawing. Make sure you print what gets returned from the method as well as the value of the balance after withdrawing. Did you try both withdrawing less and withdrawing more than the balance?
☑ Go back to these methods and change them so that if you are given a negative number, you print a complaint and do nothing. Think about what code needs to be inside the if, and how to write the condition of the if so that it is true when you do want to do the code. If a method returns, it needs to return no matter what happens. Make sure withdraw is returning a reasonable number even if the method is "doing nothing."
Throughout this assignment, if you are depositing to or withdrawing from the account, remember to use these methods!!!
Part B
☑ Create a new class Bank, with an instance variable currentAccount, of type Account. Remember that if you have a class Account, then Account is a perfectly good variable type, and is used just like String or int. Also give Bank an instance variable fee. In the following methods, whenever we need to talk to the user, create a local Scanner variable in each method. (Remember that the info on the Scanner class is linked from the class page) ☑ In Bank create a method makeAccount, which asks the user for a starting balance. Return a new Account with the balance set to the value given. Remember that asking the user for a value is different from taking a parameter. ☑ In Bank, create a method starter, which sets up currentAccount using makeAccount, and sets fee to .10 At this point, go to your main and create a Bank object. Call its starter method and print its currentAccount. Try depositing and withdrawing to the bank's currentAccount. In Bank, to provide a menu, you will create methods, mainMenu, depositMenu, and withdrawMenu. ☑ In mainMenu, In a loop, print a list of options for the user 1. Show Balance☑ In Account, add an instance variable jointAccount, which is an Account.
☑ Add a method join which takes an account, and makes each Account the other's jointAccount. So my jointAccount variable will be set to the one passed in, and the one passed in's jointAccount variable will be set to me.
Go back and change the toString so that if there is a joint account (that is, the variable is not null), we now get something like
$4583.02 ($2273 available in joint account)
This means that if there is not a joint account, we still get the original version.
☑ Add a method transferTo which takes a double amount, and if there is a joint account, withdraws amount from jointAccount and deposits it to this account If there is no jointAccount, print a complaint.
☑ Add a similar method transferFrom which takes a double amount, and if there is a joint account, moves amount in the other direction, with the same rules.
☑ In Bank, add to the main menu another option: Tools And add a method toolMenu, which is like the previous menus, but the list of options is 1. Create Joint Account☑ To the deposit menu, add the option: Transfer funds to account
and if they enter 3, transfer from the joint account to the account an amount specified by the user. After doing this, also take the fee from the main account. ☑ To the withdrawal menu, add the option: Transfer funds from account and if they enter 3, ask them how much to transfer, and then use the account's transferFrom method. After doing this, also take the fee from the joint Account.Part D
☑ In Account, add a method mergeAccounts which takes a parameter fee. It the account has at least fee as balance and there is a joint account, transfer all of the joint account's balance to this account. Then withdraws the. Finally set the jointAccount to null
☑ In Bank, add to the tool menu another option 2. Merge Accounts If they choose this option, merge the account with its jointAccount, and pass in the current fee.