My assignment is
LoanTable
Background:
When buying a home, a very important financial consideration that many buyers face is obtaining a qualifying loan from a financial institution. Interest rates can be fixed or variable and there are service charges called 'points' for taking out a loan. One 'point' is equal to 1% of the loan amount (called principal) borrowed. Taking out a loan of $150,000 with a 2 point charge will amount to a cost of $3,000 for obtaining the loan - before you ever make your first mortgage payment! Some banks and financial lending institutions offer lower interest rates but require higher points, and vice versa. Usually, the more po ints you pay, the lower the interest rate. It is helpful to know what the monthly mortgage payment will be for a given loan amount with different interest rates.
The monthly payment on a loan is determined using three inputs:
1. The amount of the loan (principal).
2. The number of years for the loan to be paid off.
3. The annual interest rate of the loan.
The formula for determining payments is:
a = (p * k * c)(c - 1)
p = principal, amount borrowed
k = monthly interest rate (annual rate/12.0)
n = number of monthly payments (years * 12)
c = (1 + k)n
a = monthly payment (interest and principal paid)
Assignment:
1. Write a program that prompts the user for the following information:
a. The amount of the loan
b. The length of the loan in years
c. A low interest rate in %
d. A high interest rate in %
2. Print out the monthly payment for the different interest rates from low to high, incremented by 0.25%.
3. A sample run output is given below:
Mortgage problem
Principal = $100000.00
Time = 30 years
Low rate = 11%
High rate = 12%
Annual Interest Rate Monthly Payment
11.00 952.32
11.25 971.26
11.50 990.29
11.75 1009.41
12.00 1028.61
4. Your program should make use of the built-in pow method located in the Math class.
5. Your program must make use of separate methods for the data input section and the printing section of the assignment.
My code is
import java.util.Scann er;
public class LoansTable {
public static void main(String args[])
{
Scanner myScanner = new Scanner(System. in);
double principalAmout;
double lowRate;
double highRate;
int years;
double monthlyPayment;
double k;
double n;
double c;
System.out.prin tln("Enter the amount of the loan you would like to take."); //User Inputs
principalAmount = myScanner.nextD ouble();
System.out.prin tln("Enter the length of the loan in years.");
years = myScanner.nextI nt();
System.out.prin tln("Enter a low interest rate in %.");
lowRate = myScanner.nextD ouble();
System.out.prin tln("Enter a high interest rate in %.");
highRate = myScanner.nextD ouble();
System.out.prin tln("Principal = $" + principalAmount );
System.out.prin tln("Time = " + years + " years");
System.out.prin tln("Low Rate = " + lowRate + "%");
System.out.prin tln("High Rate = " + highRate + "%");
for (double lowRate; lowRate <= highRate; lowRate = lowRate + 0.25)
{
k = lowRate / 12.0;
n = years * 12;
c = Math.pow((1 + k), n);
monthlyPayment = (principalAmoun t * k * c) / (c - 1);
System.out.prin tln("Your Annual Interest Rate is " + lowRate);
System.out.prin tln("Your Monthly Payment is " + monthlyPayment) ;
}
}
}
the error that shows is that it cannot find symbol principalAmount in the code.
LoanTable
Background:
When buying a home, a very important financial consideration that many buyers face is obtaining a qualifying loan from a financial institution. Interest rates can be fixed or variable and there are service charges called 'points' for taking out a loan. One 'point' is equal to 1% of the loan amount (called principal) borrowed. Taking out a loan of $150,000 with a 2 point charge will amount to a cost of $3,000 for obtaining the loan - before you ever make your first mortgage payment! Some banks and financial lending institutions offer lower interest rates but require higher points, and vice versa. Usually, the more po ints you pay, the lower the interest rate. It is helpful to know what the monthly mortgage payment will be for a given loan amount with different interest rates.
The monthly payment on a loan is determined using three inputs:
1. The amount of the loan (principal).
2. The number of years for the loan to be paid off.
3. The annual interest rate of the loan.
The formula for determining payments is:
a = (p * k * c)(c - 1)
p = principal, amount borrowed
k = monthly interest rate (annual rate/12.0)
n = number of monthly payments (years * 12)
c = (1 + k)n
a = monthly payment (interest and principal paid)
Assignment:
1. Write a program that prompts the user for the following information:
a. The amount of the loan
b. The length of the loan in years
c. A low interest rate in %
d. A high interest rate in %
2. Print out the monthly payment for the different interest rates from low to high, incremented by 0.25%.
3. A sample run output is given below:
Mortgage problem
Principal = $100000.00
Time = 30 years
Low rate = 11%
High rate = 12%
Annual Interest Rate Monthly Payment
11.00 952.32
11.25 971.26
11.50 990.29
11.75 1009.41
12.00 1028.61
4. Your program should make use of the built-in pow method located in the Math class.
5. Your program must make use of separate methods for the data input section and the printing section of the assignment.
My code is
import java.util.Scann er;
public class LoansTable {
public static void main(String args[])
{
Scanner myScanner = new Scanner(System. in);
double principalAmout;
double lowRate;
double highRate;
int years;
double monthlyPayment;
double k;
double n;
double c;
System.out.prin tln("Enter the amount of the loan you would like to take."); //User Inputs
principalAmount = myScanner.nextD ouble();
System.out.prin tln("Enter the length of the loan in years.");
years = myScanner.nextI nt();
System.out.prin tln("Enter a low interest rate in %.");
lowRate = myScanner.nextD ouble();
System.out.prin tln("Enter a high interest rate in %.");
highRate = myScanner.nextD ouble();
System.out.prin tln("Principal = $" + principalAmount );
System.out.prin tln("Time = " + years + " years");
System.out.prin tln("Low Rate = " + lowRate + "%");
System.out.prin tln("High Rate = " + highRate + "%");
for (double lowRate; lowRate <= highRate; lowRate = lowRate + 0.25)
{
k = lowRate / 12.0;
n = years * 12;
c = Math.pow((1 + k), n);
monthlyPayment = (principalAmoun t * k * c) / (c - 1);
System.out.prin tln("Your Annual Interest Rate is " + lowRate);
System.out.prin tln("Your Monthly Payment is " + monthlyPayment) ;
}
}
}
the error that shows is that it cannot find symbol principalAmount in the code.
Comment