SE-1011 Software Development 1
Lab 5: Interest Calculator

Objectives

Assignment

Scenario: You have discovered that, unknown to you, a distant relative purchased a Treasury bond for you on the day you were born. Unfortunately, you don't yet know how much it is worth. Will you be able to buy that Ferrari? or will you have to settle for a 1983 mini-van? In order to find out, you need to write a Java program that computes the value of the bond at various intervals, from its initial value to its value after some specified number of years.

Detailed requirements

In this lab, you will write a program that computes the changing value of a Treasury bond based on its initial value and % rate of return. You will incorporate conditional control statements (if-else if-else) into your program in order to provide a basic error handling mechanism for invalid inputs entered by the user. You'll also incorporate iteration statements (while, or do-while) to automatically compute the bond value at various intervals.

After reading through the following requirements, draw a flowchart (it will be more significantly more complex than any you've drawn previously). This will greatly help you in figuring out the steps needed in the actual implementation.

Your program is to present to the user a JOptionPane-based welcome message stating what it does and what it will ask the user for in terms of information, similar to that shown below (but you can customize your welcome message):

Interest on the bond is compounded daily, and formula for calculating the current value of the bond is given by

where Vc is the current value,
Vi is the initial value,
I is the annual percentage rate (note that I is 0.076 if the interest rate is 7.6%),
n is the number of days since the purchase of the bond.
 

Hints:

String output;
int x = 2;
double y = 3.5;
output.format("The value of x is %4d and the value of y is %6.2f \n", x, y );

depending on the values of x and y, of course, the contents of the String output would be different than that above. Note that the format specification used by the format() method is similar to that used in the printf() method discussed in class.

String output;
String message = ""; // initially empty
int x = 2;
double y = 3.5
output = String.format("The value of x is %4d and the value of y is %6.2f \n", x, y );
message += output; // concatenate the strings
x = 4;
y = 1.2;
output.format("The value of x is %4d and the value of y is %6.2f \n", x, y );
message += output; // concatenate again

At the end, the contents of the String message would be:

"The value of x is    2 and the value of y is 3.50
  The value of x is    4 and the value of y is 1.20
"

Lab Submission (due by end of lab)

Submit your assignment following these instructions:

  1. Hand in your flowchart to your instructor.
  2. Upload your .java file through WebCT (assignment "Lab 5: Interest Calculator").
Be sure to keep copies of all your java files, in case something gets lost.

Your grade will be based on the following criteria: