CIS 790             LOAN CALCULATOR            PROF. AUCIELLO

Topics:
		1. variable interest rate (0.00125)
		2. Format.print (controlled formatting)
        	3. Console.readInt  (from KB)
        	4. for loop ...
        	5. changing parameters in a for-loop.
        	6. math.pow method  (powerful procedure)
        	7. what does 'amortization' mean
                8. formula for calculating payments 
--------------------------------------------------------------

Write the java instructions to create the following output:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Enter Principal Amount (no commas):   157000  
Interest rate in % (use 7.5 for 7.5%):  7.00
The number of years:                      30

 With rate  6.000 your payment is $    941.29
 With rate  6.100 your payment is $    951.41
 With rate  6.200 your payment is $    961.58
 With rate  6.300 your payment is $    971.79
 With rate  6.400 your payment is $    982.04
 With rate  6.500 your payment is $    992.35
 With rate  6.600 your payment is $   1002.69
 With rate  6.700 your payment is $   1013.09
 With rate  6.800 your payment is $   1023.52
 With rate  6.900 your payment is $   1034.00
 With rate  7.000 your payment is $   1044.52
 With rate  7.100 your payment is $   1055.09
 With rate  7.200 your payment is $   1065.70
 With rate  7.300 your payment is $   1076.35
 With rate  7.400 your payment is $   1087.04
 With rate  7.500 your payment is $   1097.77
 With rate  7.600 your payment is $   1108.54
 With rate  7.700 your payment is $   1119.35
 With rate  7.800 your payment is $   1130.20
 With rate  7.900 your payment is $   1141.08
 With rate  8.000 your payment is $   1152.01

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
Note that printout starts with 1  point below and 
                   ends   with 1  point above current interest rate.

...........................................................
Following are the java instructions in English:

...........................................................
1.  Start program with an optional comment that describes it.
2.  Link with corejava libraries.
3.  Name program as "loancalc";  the name of the class object.
4.  Open bracket. followd by a statement that means this class will be 
    available to other classes, and objects in same workspace; that 
    means this method initializes and does not return a result.  That 
    has a main method, always declared public, and has as its only 
    parameter an array of Strings type used for command line parameters.               
5.  Begin bracket that defines 'main' class; define principal and 
    yearlyInterest as Doubleword, floating point variables.
6.  define years as an integer.
7.  Prompt the user to enter the loan amount, read it as a doubleword,
    and stuff it into "principal".
8.  Read in yearlyinterest from keyboard and divide by 100 before
    assigning it to a variable.
9.  Accept value for years from console.
10. Define y as a doubleword.
11. Begin a loop that starts 1 point below yearlyinterest, ends with
    1 point above, and autoincrements by 1/10 of a point.
12. Inside brackets, calc monthlyinterest = to yearlyinterest/12.
13. Calculate payment (2 line formula).
14. Print out rate    in a formatted field, without a linefeed.
15. Print out payment in a formatted field, without linefeed.
16. Print a blank line [line feed]: (advances line).  
17. Close innermost bracket (loop)
18. Close next set of brackets.
19. Close outermost set of brackets.
..................................................................
 
import corejava.*;
{ double monthlyInterest = y / 12;
  double payment = principal * monthlyInterest / 
  (1-(Math.pow((1/(1 + monthlyInterest)),years*12)));
{ public static void main(String args[])
{ double principal;       
  years = Console.readInt ("The number of years: ");
  double y;
// CIS 790       LOAN CALCULATOR   Your Name   Prof. Auciello  
   Format.print(System.out," With rate %6.3f", 100*y);
   class loancalc
   for (y= yearlyInterest - 0.01;
   y<=yearlyInterest + 0.011; y += 0.00100)
   double yearlyInterest;
   int years;
   principal = Console.readDouble ("Loan Amount (no commas):");
   yearlyInterest = Console.readDouble("Interest rate in % (use 7.5 for 7.5%): ")/100;
   Format.print(System.out," your payment is $%10.2f", payment);
   System.out.println(" ");
                 }
      }
 }
.................................................

Be sure that you save it as loancalc.java  (4 letter extension).
Compile it.  Run it.  Screen Capture it.  Paste into document.
Put into HW notebook for 100 points.
Click here to check yourself as you code