CIS 67: Homework 7

Handed out: 02/28/2007
Due: By 10pm on 03/12/2007
Email program to TA

This assignment is derived from an assignment of Professor Koffman.

Write a class to represent Certificates of Deposit (CDs). There are two types of CDs, redeemable (R) and non-redeemable (N). The kind of CD, term, and value of the CD are provided as data.
For redeemable CDs the interest rate is 3.5% for a 1 year CD and 5% for any term over 1 year.
For non-redeemable CDs the interest rate is 4% for a 1 year CD and 5.5% for any period over 1 year. [The period of time you hold a CD, called the term, will be 1 year, or 2 years, etc. never a fraction of years.]
Also, if the CD has value equal or more than $5000, the interest rate should be bumped up by 0.25%. If it is for equal or more than $10000, bump the interest rate up by 0.5%. [Note: if I have a $2000 one year redeemable CD I get 3.5% interest; if you have a $6000 one year redeemable CD you get 3.75% interest; if he has an $11000 one year redeemable CD he gets 4% interest.]

Your class should store all the data about a CD (type - a character, value - a double, and term - an integer) as instance data members. Provide all appropriate methods for the class (constructors, accessors, setters, toString, equals, clone).

Provide the method public static CD readCD(); that prompts the user to enter the required information for a CD [the term (number of years - an integer), deposit value (double), and the kind of CD (R for redeemable, and N for non-redeemable)] and returns the corresponding CD [This is the same idea as readFraction which we did in the past.].

Provide a method getAnnualInterest that calculates the interest for one year for a given amount, type and term.

Use the class Pair to represent as a pair of doubles

  class Pair 
  {
     public double first;
     public double secondt;
     public Pair(){}
     public Pair(int f, int s) {first = f; second = s;}
  }

Provide a method

    public Pair[] calcCompoundInterest() 
that calculates the Annual interest if the CD is kept for its full term. It returns an array that in position 0 holds as a Pair the initial value of the interest (i.e. 0.0) and the initial value of the CD, in position 1 holds as a Pair the interest accrued in the first year and the value at the end of the first year, in position 2 holds as a Pair the interest accrued in the second year and the value at the end of the second year, etc. Remember, the value of the CD at the end of a year is : end value = start value + interest for the year. The end value for year n becomes the start value for year n+1. Use getAnnualInterest to calculate the interest for each year. Beware that since the value of a CD changes because of the accumulation of interest, the interest rate may also change because the value of the CD may move beyond $5000 or beyond $10000

Provide a method

    public double[] calcRDifference() 
that calculates the difference in total values for a given CD depending if it is Redeemable or Non-redeemable. [It shows how much you gain by being non-redeemable.] At position 0 holds 0.0; at position 1 holds the difference in values at the end of one year depending if the CD is non-redeemable or redeemable; at position 2 holds the total difference in values at the end of two years depending if the CD is non-redeemable or redmable; etc.

The program in a loop should prompt the user to define a CD and terminate when the value entered for the CD is 0. Then for a CD the program will display first the definition of the CD, then use the results of calcCompoundInterest to display for the duration of a CD its total interest and CD value, then use the results of calcRdifference to display each year the gain of choosing a non-redeemable instead of a redeemable CD.
For example for a CD your output could look something like this (note this is just to show the form of the example).

CD with: Value = $5,500, Term = 2 years, Kind = Non-Redeemable, InterestRate = 5.75%

year	Annual interest		CD value
 0	  0.00			5500.00
 1	316.25			5816.25
 2	334.43			6150.68

year	Difference in interest
 0           0.00
 1          27.50
 2          58.02
By having a non-redeemable instead of redeemable CD you gain in total 58.025 dollars.