Java Reference
In-Depth Information
number of years, and interest rate and displays the amortization schedule for the
loan. Here is a sample run:
Loan Amount: 10000
Number of Years: 1
Annual Interest Rate: 7
Monthly Payment: 865.26
Total Payment: 10383.21
Payment# Interest Principal Balance
1 58.33 806.93 9193.07
2 53.62 811.64 8381.43
...
11 10.0 855.26 860.27
12 5.01 860.25 0.01
Note
The balance after the last payment may not be zero. If so, the last payment should be
the normal monthly payment plus the final balance.
Hint : Write a loop to display the table. Since the monthly payment is the
same for each month, it should be computed before the loop. The balance
is initially the loan amount. For each iteration in the loop, compute the
interest and principal, and update the balance. The loop may look like this:
for (i = 1 ; i <= numberOfYears * 12 ; i++) {
interest = monthlyInterestRate * balance;
principal = monthlyPayment - interest;
balance = balance - principal;
System.out.println(i + "\t\t" + interest
+ "\t\t" + principal + "\t\t" + balance);
}
*5.23
( Demonstrate cancellation errors ) A cancellation error occurs when you are
manipulating a very large number with a very small number. The large number
may cancel out the smaller number. For example, the result of 100000000.0 +
0.000000001 is equal to 100000000.0 . To avoid cancellation errors and obtain
more accurate results, carefully select the order of computation. For example, in
computing the following series, you will obtain more accurate results by comput-
ing from right to left rather than from left to right:
1
2
1
3
1
n
1
+
+
+ c +
Write a program that compares the results of the summation of the preceding
series, computing from left to right and from right to left with n = 50000 .
*5.24
( Sum a series ) Write a program to sum the following series:
1
3
3
5
5
7
7
9
9
11
11
13
95
97
97
99
VideoNote
Sum a series
+
+
+
+
+
+ g +
+
 
Search WWH ::




Custom Search