CSCI 161: CD Interest
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 REQUIRED METHODS listed below, with the EXACT same SPELLING for method names and parameters.
Input Specification
Ask the user for an initial balance, annual rate, and the number of years the money will be invested. The balance and rate will be real numbers, while the number of years must be an integer.
Use PRECISELY the format below with the EXACT same SPACING.
Please enter the initial balance: <user input>
Please enter the interest rate : <user input>
Please enter the number of years: <user input>
Output Specification
Output an introductory message, prompts, and then the table. The sample output below assumes the user entered an initial balance of 1000, an interest rate of 6.50, and a number of years of 10. Note well the FORMATTING (spacing and justification) used. You may assume numbers will not overflow their columns.
This program will calculate the interest earned
on a CD over a period of several years.
Please enter the initial balance: 1000
Please enter the interest rate : 6.5
Please enter the number of years: 10
Year Balance Interest New Balance
---- ------- -------- -----------
1 1,000.00 65.00 1,065.00
2 1,065.00 69.23 1,134.23
.
.
.
10 ...
Required Methods
Include at LEAST the following methods.
// Inform user what program will do
void printIntro ()
// Print the header followed by all the rows.
void printTable (int numRows, double balance, double rate)
// Print one row of table. "interest" is a dollar amount,
// not a rate.
void printRow (int rowNum, double balance, double interest)
// Calculate interest given a balance and percentage rate (like 7.2%)
double calcInterest (double balance, double rate)
Hints
Use ONE Scanner object to read the input values, and read them in “main”.
Do NOT worry about formatting the table until you get the logic
correct. Once you do get the logic correct, use
System.out.printf
to format the four table columns (Year,
Balance, Interest, and New Balance). To learn about printf
see Section 4.3 (Text Processing) of the text or the slides we went
over. As an example format string, %,7d
will print an
integer in a field width of 7 characters with commas inserted as
necessary.
The following width guide may be of use:
111111111122222222223333333333444444
123456789012345678901234567890123456789012345
Year Balance Interest New Balance
---- ------- -------- -----------
Style
Use good programming style:
- Write comments
- Choose mnemonic, meaningful variable names (e.g. balance, interestRate)
- Indent consistently (Ctrl+Shift+F` will format your code)
- Remember the comment block at the top of your program
Submission
Please name your program CDInterest.java
Submit the Java source code file on Autolab under the “CD Interest” assignment.
Grading
- 20 points will be awarded for having a well-formatted, well-documented source code file. This includes your name, date, description, and comments throughout the program. This also includes other style requirements, such as method naming conventions. NOTE: The autograder will not display these points.
- 20 points will be awarded for having proper input from a user.
- 40 points will be awarded for having methods with correct parameters and return types
- 20 points will be awarded for having proper output that matches EXACTLY
- NOTE: if your program does not compile/run, the highest score you will earn will be a 20/100