Write a program that lets the user enter the loan amount and loan period in number of years and displays the monthly and total payments for each interest rate starting from 5% to 8%, with an increment of 1/8.
import java.util.*;
public class Interest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double loanamount = sc.nextDouble();
System.out.println("Loan Amount: "+loanamount);
int years = sc.nextInt();
System.out.println("Number of Years: "+years);
System.out.println("Interest Rate Monthly Payment Total Payment");
for (double i = 5.0; i <= 8; i += 0.125)
{
System.out.printf("%-5.3f", i);
System.out.print("% ");
double monthlyir = i / 1200;
double monthlyPayment = loanamount * monthlyir / (1- 1 / Math.pow(1 + monthlyir,years * 12));
System.out.printf("%-19.2f", monthlyPayment);
System.out.printf("%-8.2f\n",(monthlyPayment * 12) * years);
}
}
}
output:
Loan Amount: 10000.0
Number of Years: 5
Interest Rate Monthly Payment Total Payment
5.000% 188.71 11322.74
5.125% 189.29 11357.13
5.250% 189.86 11391.59
5.375% 190.44 11426.11
5.500% 191.01 11460.70
5.625% 191.59 11495.35
5.750% 192.17 11530.06
5.875% 192.75 11564.84
6.000% 193.33 11599.68
6.125% 193.91 11634.59
6.250% 194.49 11669.56
6.375% 195.08 11704.59
6.500% 195.66 11739.69
6.625% 196.25 11774.85
6.750% 196.83 11810.08
6.875% 197.42 11845.37
7.000% 198.01 11880.72
7.125% 198.60 11916.14
7.250% 199.19 11951.62
7.375% 199.79 11987.16
7.500% 200.38 12022.77
7.625% 200.97 12058.44
7.750% 201.57 12094.18
7.875% 202.17 12129.97
8.000% 202.76 12165.84
import java.util.*;
public class Interest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double loanamount = sc.nextDouble();
System.out.println("Loan Amount: "+loanamount);
int years = sc.nextInt();
System.out.println("Number of Years: "+years);
System.out.println("Interest Rate Monthly Payment Total Payment");
for (double i = 5.0; i <= 8; i += 0.125)
{
System.out.printf("%-5.3f", i);
System.out.print("% ");
double monthlyir = i / 1200;
double monthlyPayment = loanamount * monthlyir / (1- 1 / Math.pow(1 + monthlyir,years * 12));
System.out.printf("%-19.2f", monthlyPayment);
System.out.printf("%-8.2f\n",(monthlyPayment * 12) * years);
}
}
}
output:
Loan Amount: 10000.0
Number of Years: 5
Interest Rate Monthly Payment Total Payment
5.000% 188.71 11322.74
5.125% 189.29 11357.13
5.250% 189.86 11391.59
5.375% 190.44 11426.11
5.500% 191.01 11460.70
5.625% 191.59 11495.35
5.750% 192.17 11530.06
5.875% 192.75 11564.84
6.000% 193.33 11599.68
6.125% 193.91 11634.59
6.250% 194.49 11669.56
6.375% 195.08 11704.59
6.500% 195.66 11739.69
6.625% 196.25 11774.85
6.750% 196.83 11810.08
6.875% 197.42 11845.37
7.000% 198.01 11880.72
7.125% 198.60 11916.14
7.250% 199.19 11951.62
7.375% 199.79 11987.16
7.500% 200.38 12022.77
7.625% 200.97 12058.44
7.750% 201.57 12094.18
7.875% 202.17 12129.97
8.000% 202.76 12165.84
No comments:
Post a Comment