CSCI 161: Introduction to Programming I
Homework 2: CD Interest (Return Values, Math Methods)
Due at beginning of next lab period

Overview

Calculate the interest earned on a certificate of deposit (CD) over a specified period. Prompt the user for an initial balance, an annual rate, and the number of years the money will be invested. Output a table that shows the starting balance, interest earned, and updated balance at the end of each year.

Use at least the methods required below. You may use additional methods to further decompose the problem.

Include a comment block at the very beginning of your program with the name of the program, your name, date, course number, and a description of the program. Use good programming style: use meaningful variable names, write appropriate comments for each method and loop, indent appropriately (Control-Shift-F in Eclipse), and use white space and method separators to make your program more readable. Points will be deducted for not following these guidelines.

Input Specification

Note: the numbers that are underlined and in bold are input values. Also, the interest rate is entered as a percentage, so it must be modified to use in the interest calculations.

Print Introductory Message Describing Program

Please enter the initial balance: 1000.00
Please enter the interest rate  : 6.50
Please enter the number of years: 10

Output Specification

Year	Balance	     Interest	New Balance
----	-------	     --------	-----------
1	1000.0	     65.0	1065.0
2	1065.0	     69.23	1134.22
3	1134.22	     73.72	1207.95
4	1207.95	     78.52	1286.47
5	1286.47	     83.62	1370.09
6	1370.09	     89.06	1459.14
7	1459.14	     94.84	1553.99
8	1553.99	     101.01	1655.0
9	1655.0	     107.57	1762.57
10	1762.57	     114.57	1877.14

Required Methods

void   printIntro   () 		// inform user what program will compute
void   printTable   (int numRows, double balance, double rate)  // print the entire table
void   printRow     (int rowNum, double balance, double interest)  // print just one row of the table
double calcInterest (double balance, double rate)  // calculate the interest dollar amount
double roundTo2Dec  (double value)  // round "value" to 2 decimal places

Hints

Use one Scanner object to read the input values. Read the input values in "main".

Extra Credit

For extra credit (+5 points), format the balance, interest, and updated balance as currency using the NumberFormat class of the java.text package (2134.837 prints as $2,134.84). Review the methods here on formatting currency. Make the call to "roundTo2Dec" a comment (insert "//" at the beginning of the line), and use a "NumberFormat" currency instance instead. Submit only one program, and ensure you have "roundTo2Dec" implemented correctly.

Submission

Submit this as HW2.


Dr. Blaise W. Liffick