Question

In: Computer Science

Write a program that lets the user enter the loan amount, number of years, and interest...

Write a program that lets the user enter the loan amount, number of years, and interest rate and displays the amortization schedule for the loan.

Steps: 1) Create scanner

2) Prompt the user to enter loan amount and declare double variable and relate to scanner input

3) Prompt the user to enter number of years and declare integer years and relate to scanner input

4) Prompt the user to enter annual interest rate and declare double variable and relate to scanner input

5) Calculate monthly interest rate: first create a double variable called monthlyRate which is equal to annualRate divided by 1200

6) Calculate monthly payement: first create double variable called monthlyPayement which is equal to loanAmount times monthlyRate divied by (1 - 1 / Math.pow(1 + monthlyRate, years * 12));

7) Display in console monthlyPayement

8) Display in console total amount with formula inside of prompt (monthlyPayement*12) * years);

9) Create so called amortization schedule: first create double variable called balance which is equal to loanAmount, principal, interest;

10) System.out.println ("Payment# Interest Principal Balance"); for (int i = 1; i <= years * 12; i++) { interest = monthlyRate * balance; principal = monthlyPayment - interest; balance = balance - principal; System.out.printf("%-13d%-13.2f%-13.2f%.2f\n", i, interest, principal, balance); }

Solutions

Expert Solution

Code For Above Problem:


import java.util.Scanner;

public class AmortizationSchedule {

        public static void main(String[] args) {

                // Steps: 1) Create scanner
                Scanner sc = new Scanner(System.in);
                /* 2) Prompt the user to enter loan amount and declare double variable and
                 * relate to scanner input
                 */
                System.out.print("Enter Loan Amount: ");
                double loanAmount=sc.nextDouble();      
                /*3) Prompt the user to enter number of years and declare integer years 
                 * and relate to scanner input
                 */
                System.out.print("Enter Number Of Years: ");
                int years=sc.nextInt();
                /*4) Prompt the user to enter annual interest rate and declare double
                 *  variable and relate to scanner 
                 */
                System.out.print("Enter Annual Interest Rate: ");
                double annualRate=sc.nextDouble();
                
                /*5) Calculate monthly interest rate: first create a double variable 
                 * called monthlyRate which is equal to annualRate divided by 1200
                 */
                double monthlyRate=annualRate/1200;
                
                /*6) Calculate monthly payement: first create double variable called
                 *  monthlyPayement which is equal to
                 *  loanAmount times monthlyRate divied by (1 - 1 / Math.pow(1 + monthlyRate, years * 12));
                 */
                double monthlyPayment=(loanAmount*monthlyRate)/(1 - 1 / Math.pow(1 + monthlyRate, years * 12));
                
                /*
                 * 7) Display in console monthlyPayement
                 */
                System.out.println("Monthly Payment: "+monthlyPayment);
                
                /*
                 * 8) Display in console total amount with formula inside of prompt (monthlyPayement*12) * years);
                 */
                System.out.println("Total Amount: "+(monthlyPayment*12) * years);
                
                /*
                 * 9) Create so called amortization schedule:
                 * first create double variable called balance which is equal to loanAmount, principal, interest;
                 */
                
                double balance=loanAmount;
                double principal,interest;
                
                /*10) System.out.println ("Payment# Interest Principal Balance"); 
                 * for (int i = 1; i <= years * 12; i++) 
                 * { interest = monthlyRate * balance;
                 *  principal = monthlyPayment - interest; 
                 *  balance = balance - principal; 
                 *  System.out.printf("%-13d%-13.2f%-13.2f%.2f\n", i, interest, principal, balance); 
                 *  }
                 */
                
                 System.out.println ("Payment# Interest Principal Balance"); 
                 for (int i = 1; i <= years * 12; i++) 
                 { 
                         interest = monthlyRate * balance; 
                         principal = monthlyPayment - interest; 
                         balance = balance - principal; 
                         System.out.printf("%-13d%-13.2f%-13.2f%.2f\n", i, interest, principal, balance); 
                 }
                 sc.close();
        }

}

Sample Run Results:

Enter Loan Amount: 50000
Enter Number Of Years: 2
Enter Annual Interest Rate: 10
Monthly Payment: 2307.2463168758336
Total Amount: 55373.91160502001
Payment# Interest Principal Balance
1            416.67       1890.58      48109.42
2            400.91       1906.33      46203.09
3            385.03       1922.22      44280.87
4            369.01       1938.24      42342.63
5            352.86       1954.39      40388.24
6            336.57       1970.68      38417.56
7            320.15       1987.10      36430.46
8            303.59       2003.66      34426.80
9            286.89       2020.36      32406.44
10           270.05       2037.19      30369.25
11           253.08       2054.17      28315.08
12           235.96       2071.29      26243.79
13           218.70       2088.55      24155.24
14           201.29       2105.95      22049.29
15           183.74       2123.50      19925.79
16           166.05       2141.20      17784.59
17           148.20       2159.04      15625.55
18           130.21       2177.03      13448.52
19           112.07       2195.18      11253.34
20           93.78        2213.47      9039.87
21           75.33        2231.91      6807.96
22           56.73        2250.51      4557.45
23           37.98        2269.27      2288.18
24           19.07        2288.18      -0.00

Images Of Code:

Image Of Sample Run Results:


Related Solutions

How to write a C++ program that lets the user enter a string and checks if...
How to write a C++ program that lets the user enter a string and checks if it is an accepted polynomial. Accepted polynomials need to have one term per degree, no parentheses, spaces ignored.
Program on Visual Basic, VBA Create an application that lets the user enter a number of...
Program on Visual Basic, VBA Create an application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
Time Calculator Create a C++ program that lets the user enter a number of seconds and...
Time Calculator Create a C++ program that lets the user enter a number of seconds and produces output according to the following criteria: • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
C++ Write a program that lets the user enter a two letters which are f and...
C++ Write a program that lets the user enter a two letters which are f and s with a length of 5. And outputs how many times it was occurred and lists the 2 most repeating pattern with 5lengths of f and s. The output display should always start at three-f(s) .Include an option where user can retry the program. Example: Input: sssfsfsfssssfffsfsssssfffsffffsfsfssffffsfsfsfssssfffffsffffffffffffssssssssfffsffffsssfsfsfsfssssfffsssfsfsffffffssssssffffsssfsfsfsss Output: The most repeating 5lengths of pattern is: fffsf and occurred 6times. Output2: The second most repeating...
Write a C++ program that lets the user enter the total rainfall for each of 12...
Write a C++ program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year,     the average monthly rainfall,     and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November,...
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
Time Calculator ( PROGRAM VBA EXCEL) Create a application that lets the user enter a number...
Time Calculator ( PROGRAM VBA EXCEL) Create a application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than...
Write a java program that lets the user to enter any two integers and weave them...
Write a java program that lets the user to enter any two integers and weave them digit by digit and print the result of weaving their digits together to form a single number. Two numbers x and y are weaved together as follows. The last pair of digits in the result should be the last digit of x followed by the last digit of y. The second-to-the-last pair of digits in the result should be the second-to- the-last digit of...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol,...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol, omg, omw etc.), then translates it into English (e.g. laughing out loud, oh my god, on my way etc.). Also provide a mechanism to translate text written in English into SMS Language. needs to be able to translate at least 10 sms words
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT