Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Assignment #9 (The ArrayList Class) The Problem A banking institutio

ID: 3817372 • Letter: P

Question

Programming Assignment #9

(The ArrayList Class)

  The Problem

A banking institution offers certificates of deposit (CD's) with a variety of interest rates, and maturities of 1, 3, 5, and 10 years. Interest is always compounded - daily, monthly, or quarterly.

Write a Java program that will compute the following information at yearly intervals, for any number of such CD's:

the accumulated value (principal plus interest earned to date)

the interest earned for the year

the total interest earned to date

Assume that a year always consists of exactly 365 days

Output will be a series of 10 annual reports:

Reports will be in table form with appropriate column headings. There will be one row of the table for each active CD, which will include all the data along with the accumulated value, interest earned for the year, and total interest earned to date.

Each report will also print the total accumulated value, total interest earned for the year, and grand total of interest earned to date for all active CD’s.

Once a CD reaches maturity, it will stop earning interest and will not appear in any future reports. E.g., a CD with a maturity of 5 years will appear in the reports for years one through five, but not thereafter.

The CD Class

Begin by creating a class to model a CD. Each CD object "knows" its own principal, interest rate, maturity, and compounding mode (private instance variables). The class has “get” methods to return this data and a method to compute and return the accumulated value.

The CDList Class

Now create a class to maintain a list of CDs. You will need methods to add a CD to the list and to print an annual report.

The Driver (i.e., "Test") Class

Your test class or "driver" class will read data for any number of CDs from a file that I will supply. Each line (i.e., “record”) of the file will contain the data – principal, interest rate - as an annual per cent - , maturity, and compounding mode for one CD.

Create a CD object from the data in each record of the file and add it to the list. Then print the reports.

Additional Specifications

Your CDList class must use a generic ArrayList-of-CD as the principal (no pun intended) data structure

Your test class is to read the data file one time only. No credit will be given for programs that read the data file more than once

Each report must be neatly formatted with all values neatly aligned in columns and all monetary values rounded to 2 decimal places and preceded by a “$”

Make sure your program is well documented with both Javadoc and “internal” comments and adheres to the style conventions discussed in class.

The accumulated value (i.e., principal plus interest earned), A, is given by the formula:

                r    nt

      A = p ( 1 + ———— )

                n

           where

p = principal

n = number of times compounded per year

r = annual interest rate, expressed as a decimal

t = elapsed time in years (not the maturity!)

Hint: The method that computes and returns the accumulated value requires one parameter – the elapsed time in years

Explanation / Answer

import java.util.Scanner;

public class CompoundInterest {

   public static void main(String[] args) {

      Scanner input = new Scanner(System.in);

      double principal = 0;

      double rate = 0;

      double time = 0;

      double compoundInterest = 0;

   

      System.out.print("Enter the Principal amount : ");

      principal = input.nextDouble();

      System.out.print("Enter the Rate : ");

      rate = input.nextDouble();

      System.out.print("Enter the Time : ");

      time = input.nextDouble();

      compoundInterest = principal * Math.pow((1 + rate/100),time);

   

      System.out.println("");

      System.out.println("The Compound Interest is : "

     + compoundInterest);

   

   }

}