BankAccounts 2

Part I

Here is a test program for the part1 and part 2. You will need to uncomment lines to make it work. Copy it to a new class.

  1. Suppose the bank wants to keep track of how much money is in all BankAccounts.
    • Declare a private static variable to represent this sum.
    • Add code to constructor and necessary methods(deposit...) that will manage this variable.
    • Add a static method public double getTotalMoney that returns the total amount of money in all BankAccounts. Think about why this method should be static – its information is not related to any particular BankAccount.

     

  2. Add a method public void close() to your BankAccount class. This method should close the current BankAccount by appending “CLOSED” to the BankAccount name and setting the balance to 0. (The BankAccount number should remain unchanged.) This is going to affect how much money the bank has. Deal with this.
  3.  

  4. Add a method: public static BankAccount consolidate(BankAccountacct1,BankAccountacct2) to your BankAccount class that creates a new BankAccount whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new BankAccount should be returned. Two important rules of consolidation:
    • header would look like: public static BankAccount consolidate(BankAccount acct1, BankAccount acct2)
    • Only BankAccounts with the same name can be consolidated. The new BankAccount gets the name on the old BankAccounts but a new BankAccount number.
    • Two BankAccounts with the same number cannot be consolidated. Otherwise this would be an easy way to double your money!
    Check these conditions before creating the new BankAccount. If either condition fails, do not create the new BankAccount or close the old ones; print a useful message and return null.

Part II Transfering funds

  1. Add a method public void transfer(BankAccount receivingAcct, double amount) to the BankAccount class that allows the user to transfer funds from one bank BankAccount to another. If you call acct1.transfer(receivingAcct,957.80) should transfer $957.80 from acct1 to receivingAcct. Be sure to clearly document which way the transfer goes!
  2. Test this out either in bluej or ecilpse (in a test class).
  3. Add a static method to the BankAccount class that lets the user transfer money between two BankAccounts without going through either BankAccount. You can (and should) call the method transfer just like the other one – you are overloading this method. Your new method should take two BankAccount objects and an amount and transfer the amount from the first BankAccount to the second BankAccount. The signature will look like this:


  4. public static void transfer(BankAccount sendingAcct, BankAccount receivingAcct, double amount)

  5. Test this

     

Add these methods to BankAccount:

public static BankAccount consolidate(BankAccount acctOne, BankAccount acctTwo) {
		// TODO Auto-generated method stub
		return null;
	}

	public void transfer(BankAccount receivingAcct, double amount) 
	{
		// TODO Auto-generated method stub
		
	}

	public static void transfer(BankAccount sendingAcct, BankAccount receivingAcct, double amount)
	{
		// TODO Auto-generated method stub
		
	}           
            

 

Extra Credit

Start with this Bank class. This class will be an interface for bank workers. When the constructor is called print out a menu of choices for the user. Those choices

  • a. create new account
  • b. select individual account
  • c. consolidate accounts (this will only work if there are atleast 2 accounts and you have one free)
  • d. transfer funds
  • e. list open accounts
  • f. list bank info
  • g. exit

If b is chosen

  • a. make deposit
  • b. make withdrawl
  • c. close
  • d. exit to main menu

Have the ability to have at least 3 accounts.

MyOnlineGrades.com @2018