Question: Java Language Write a class InterestAcct representing an interest-bearing bank account. It should have instance variables for the current balance, and for the rate of

Java Language

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+20]

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.

Person Class File

package personfile; /** * simple class representing a person * with a family full of reference variables **/ public class Person { // primitive variable describing this person private int age; // Strings are reference variables private String name; // reference variables -- the family // (this would be a terrible way to store relationships for actual humans!!) private Person mother; private Person father; private Person sister; private Person brother; private Person daughter; private Person son; /* Constructors ---------------------------------- */ /** * default constructor **/ public Person() { // set up default values this.name = "John Smith"; this.age = 0; // don't try to get space for family -- // infinite loop hell! // these are not needed, // but make default vals explicit this.mother = null; this.father = null; this.sister = null; this.brother = null; this.daughter = null; this.son = null; } /** * parameterized constructor -- no family **/ public Person(String n, int a) { this(); this.setName(n); this.setAge(a); } /** * parameterized constructor -- takes parents only **/ public Person(String n, int a, Person mom, Person dad) { this(n, a); this.setMother(mom); this.setFather(dad); } /** * parameterized constructor -- takes whole family **/ public Person(String n, int a, Person mom, Person dad, Person sis, Person bro, Person dau, Person sonny) { this(n, a, mom, dad); this.setSister(sis); this.setBrother(bro); this.setDaughter(dau); this.setSon(sonny); } /* Accessors and Mutators -------------------------- */ /** * accessor for name **/ public String getName() { return this.name; } /** * mutator for name **/ public void setName(String val) { this.name = val; } /** * Accessor for age **/ public int getAge() { return this.age; } /** * mutator for age **/ public void setAge(int val) { // set sane age range if (val >= 0 && val < 125) { this.age = val; } } /** * Accessor for mother **/ public Person getMother(){ return this.mother; } /** * Mutator for mother **/ public void setMother(Person newvalue){ if (newvalue != null) { this.mother = newvalue; } } /** * Accessor for father **/ public Person getFather(){ return this.father; } /** * Mutator for father **/ public void setFather(Person newvalue){ if (newvalue != null) { this.father = newvalue; } } /** * Accessor for sister **/ public Person getSister(){ return this.sister; } /** * Mutator for sister **/ public void setSister(Person newvalue){ if (newvalue != null) { this.sister = newvalue; } } /** * Accessor for brother **/ public Person getBrother(){ return this.brother; } /** * Mutator for brother **/ public void setBrother(Person newvalue){ if (newvalue != null) { this.brother = newvalue; } } /** * Accessor for daughter **/ public Person getDaughter(){ return this.daughter; } /** * Mutator for daughter **/ public void setDaughter(Person newvalue){ if (newvalue != null) { this.daughter = newvalue; } } /** * Accessor for son **/ public Person getSon(){ return this.son; } /** * Mutator for son **/ public void setSon(Person newvalue){ if (newvalue != null) { this.son = newvalue; } } /** * return true if the given Person is my sibling **/ public boolean sibling(Person other) { // nonexistent Persons are not my sibling if (other == null) { return false; } // sibling if we have same mother if (this.mother != null && other.mother != null && this.mother == other.mother) { return true; } // sibling if we have same father if (this.father != null && other.father != null && this.father == other.father) { return true; } // any other case, not siblings return false; } /** * give information about this person and the family * return information as a string **/ public String toString() { // build up the string through concatenation String str = this.name + " is " + this.age + " year" + (this.age ==1 ? "" : "s" )+" old. "; if (this.getMother() != null) { str += "mother is " + this.getMother().getName() + " "; } if (this.getFather() != null) { str += "father is " + this.getFather().getName() + " "; } if (this.getSister() != null) { str += "sister is " + this.getSister().getName() + " "; } if (this.getBrother() != null) { str += "brother is " + this.getBrother().getName() + " "; } if (this.getDaughter() != null) { str += "daughter is " + this.getDaughter().getName() + " "; } if (this.getSon() != null) { str += "son is " + this.getSon().getName() + " "; } return str; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!