Methods


Methods

Person.java
PersonTestHarness.java

Deitel 3, 6


Classwork

Write a class InterestAcct representing an interest-bearing bank account. It should have instance variables for the current balance, and for the rate of interest.  Also add the Person class above to your project and give InterestAcct an instance variable owner of type Person.

Throughout the class, use the this.notation for all instance vars and calls to methods within the class.

Do not allow the the balance or rate of interest in the account to be 0 or below (which kind of method is responsible for ensuring rules like this?). 

Have at least one parameterized constructor in your class as well as a default constructor, and chain them together. 

Go into the Person class and add an instance variable bank of type InterestAcct, and accessor and mutator for it.  In the toString, if the person has an account, include their balance in the result.

In InterestAcct, add a method newOwner, which takes a Person.  If the Person is not null, make them the new owner and set the new owner's bank to the InterestAccount.

In the Person class, add a method swapAccounts, which takes another Person.  If the other Person is not null, and has an account, swap accounts with them (not just swap balances, swap whole accounts!).  Think about how this should happen so that everything gets updated appropriately

Add a method to InterestAcct, merge, which takes another InterestAcct.  If the other account is not null, add the balance minus $0.01 from the other account to this account's balance, and leave the other account's balance at $0.01.

Add to your InterestAcct class a method compoundTotal which takes an int for a number of years. This method should return the projected amount the account would have after the given number of years, using the rate of interest and the balance instance variables (hint: if I ask the bank to say how much I will have in 10 years, does my balance magically jump to that amount?).

If x is the initial amount in an interest bearing bank account with a rate r of interest, then at the end of one year, the amount in the account is x(1+r).

After two years, the amount is (x(1+r))(1+r) = x(1+r)(1+r) . After three years, x(1+r)(1+r)(1+r), and so on.

You do not need any special Java math methods/exponentiation; the loops we have covered are enough. (hint: the code to do this is not at all complex)

In main, set up some accounts and owners and make sure these work.


[EC]

To InterestAcct, add  a method findNextOfKin that, if the owner is not null,  returns the first family member of owner it finds in the order (daughter, son, sister, brother, mother, father) that is not null. If they are all null, return null.

Also add a method death().  In this method,  if there was a next of kin, deduct a 10% administrative fee from the balance and then, if the next of kin has an account merge this account into it.  If they have no account, they become the new owner.  If there wasn't a next of kin report that the bank claims all the money in the account as abandoned and set the balance to $0.01. 

In your main, set up several related people and check that they can inherit each other's accounts.  You should check that you can have two deaths in a row and follow to a nextOfKin's nextOfKin.