You should allow the user to enter three numbers


CS 1063 Project 1: Tables for Simple Interest
The Tables Class
Objectives
This is one of three major programming projects this semester. You may NOT collaborate on this project. While you may ask for assistance in debugging, this project should be ENTIRELY your own work.

Other objectives include:

Use static methods.
Use local variables.
Use arithmetic expressions.
Use Scanner to input values.
Use a class constant.
Use for loops.

Hand-in Requirements

All projects and laboratories will be submitted electronically through Blackboard. Zip up your entire project directory to submit as the source. (Right click on the project folder and follow Send To > Compressed (zipped) Folder or 7-Zip > Add to "project1.zip".) The project folder should in clude the following:

Tables.java
TablesOutput.txt

Tasks

Write a program that prints

Project 1 written by YOURNAME

and calls two methods:

Print a table showing the value of an account with simple interest added annually. This method should ask the user to enter the original value of the account, the annual interest rate, and the number of years that should be calculated.
Print a table showing the value of an account with simple interest added quarterly. This method also needs to ask the user to enter the original value of the account, the annual interest rate, and the number of years that should be calculated.

Here is an example of what your output should look like (user input is in bold and underlined):

Enter original amount: 1000
Enter annual interest rate: 4
Enter years: 5

Year Value
0 1000.0
1 1040.0
2 1080.0
3 1120.0
4 1160.0
5 1200.0


Enter original amount: 1000
Enter annual interest rate: 4
Enter years: 5

Year Q1 Value Q2 Value Q3 Value Q4 Value
1 1010.0 1020.0 1030.0 1040.0
2 1050.0 1060.0 1070.0 1080.0
3 1090.0 1100.0 1110.0 1120.0
4 1130.0 1140.0000000000002 1150.0 1160.0
5 1170.0 1180.0 1190.0 1200.0

Sometimes, a calculation might print out a lot of digits. This is because of roundoff errors when you use doubles. At this point, don't worry too much about it. If it bothers you too much, a way of fixing this problem in this project will be described below.
Details
The Console

You will need to use Scanner to obtain input from the keyboard. You should declare a class constant of type Scanner named CONSOLE at the beginning of your class; you should store new Scanner(System.in) in CONSOLE. See examples in the Chapter 2 lecture notes and in the Laboratory 2 assignment.
Table for Simple Interest Calculated Annually

Suppose the original amount of money is p, the annual interest rate is r, and the number of years is y. Then, using simple interest, the value v after y years is:

v = p * (1 + y * r / 100) 

In the first method, you should allow the user to enter three numbers, p, r, and the maximum value for y. p and r should be doubles. The table should show the results for different values of y, from 0 to the maximum value. For example, the user might want to print the values from year 0 to year 10.

After obtaining values from the user, your method should print a header for each column, and a line for each value of y and b. Use tab characters (t) to align the columns. See the example output shown above.

You can use a for loop that counts from 0 to the maximum value for y. Inside the loop, you should calculate v and print out one line.
Table for Simple Interest Calculated Quarterly

Suppose the original amount of money is p, the annual interest rate is r, and it is quarter q in year y. That is, in any given year, you will have a 1st quarter, 2nd quarter, 3rd quarter, and a 4th quarter, so q should store the value 1, 2, 3 or 4. Then, using simple interest, the value v after quarter q in year y is:

v = p * (1 + (y - 1 + q / 4) * r / 100) 

The (y - 1 + q / 4) is a bit of trick. At the end of quarter q of year y, a total of y - 1 years have passed plus q quarters. For example, at the end of the 3rd quarter in the 1st year, a total of 0 years plus 3 quarters have passed. [A similar example is that if you are a freshman, then this is your 1st year of college, but you haven't have a full year of college yet.]

For the second method, you should print the result of v for different values of y and q.

Just like the first method, in the second method, you should allow the user to enter three numbers, p, r, and the maximum value for y. p and r should be doubles. The table should show the results for different values of y, from 1 to the maximum value. For example, the user might want to print the quarterly values from year 1 to year 7.

Then, you should print a line for each value of y, from 1 to its maximum value. The first column should be the value of y. The following columns should be the value of v after quarter q, for different values of q.

Let's consider the pseudocode for this method step-by-step.

Pseudocode for Printing the Table for Simple Interest

Obtain values from the user.
Print headers.
Print the values in the table.

The headers for the columns need to printed in the right order with the appropriate spacing.

Pseudocode for Printing Headers

Print "Year" and a tab.
For each value of q from 1 to 4:
Print "Q", q, " Value", and a tab (maybe two tabs).
Print a newline.

Printing the values in the table requires a double loop. You will get fewer points if do this without a double loop.

Pseudocode for Printing the Values in the Table

For each value of y from 1 up to its maximum value:
Print y and a tab.
For each value of q from 1 to 4:
Calculate v.
Print v and a tab (maybe two tabs).
Print a newline.

The columns should be correctly lined up at least for the above examples, assuming no roundoff errors.
Avoiding Roundoff

If you want to avoid seeing roundoff errors (and get two digits after the decimal point) when printing a dollar value, replace:

System.out.print(v);

with:

System.out.printf("%.2f", v);

This doesn't actually avoid roundoff errors, it just hides them from you. See the book's and Java's documentation on printf for more information.
Rubric

 If your program has a method that correctly prints a table for simple interest calculated annually.
 For printing the table's headers.
 For prompting the user for three numbers (the original amount, the interest rate, and the number of years).
 For a for-loop that prints each row of the table.
 For properly calculating simple interest.
 For properly formatting the table into columns using tabs.

 If your program has a method that correctly prints simple interest calculated quarterly.
 For printing the table's headers.
 For prompting the user for three numbers (the original amount, the interest rate, and the number of years).
[5 Points] For properly nesting the two for loops, including printing the correct numbers, and properly formatting the table into columns using tabs.


If the main method of your program prints "Project 1 written by [...]" and calls the two other methods.
If your submission was a Zip file named project1.zip containing a folder named project1, which contains the other files.
If your Java program was in a file named Tables.java.
If the output of your Java program was in a file named TablesOutput.txt.
If your program contains a comment that describes what the program does and contains a descriptive comment for each method.
If your program is indented properly. 

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: You should allow the user to enter three numbers
Reference No:- TGS099285

Expected delivery within 24 Hours