PLEASE DON\'T USE COMPEX TOPICS ONLY, use scanners, peramathers, methods.....but
ID: 3549666 • Letter: P
Question
PLEASE DON'T USE COMPEX TOPICS ONLY, use scanners, peramathers, methods.....but nothing too complex..This is the 4th week of my CS 1 class anyway.
HERE is the Equation without the extra stuff, it's all I have to work from ===
// Compute result and report
months = MONTHS_IN_YEAR * years;
monthlyRate = (ratePercent / 100.0) / MONTHS_IN_YEAR ;
payment = loan * monthlyRate * Math.pow(1 + monthlyRate, months) /
(Math.pow(1 + monthlyRate, months) - 1);
Write a program that computes the monthly loan payment, given the loan amount (a
double value), the interest, as a percent % (a double value), and the number of years to
repay the loan (an int value). The calculation is to be performed in a method that is
called from main(). In main(), the calling method, you are to solicit the following values:
1. Loan amount, which is used for all calculations
2. The starting number of years to repay the loan, ending number of years to repay
the loan, and the incremental years.
3. The starting interest rate, as a %, the ending interest rate, as a %, and the
incremental interest rate, as a %.
You will the use for loops to create tables of monthly payments based on the number of
years to repay the loan, the table containing interest rate and the monthly loan payment.
The outer for loop will start with the starting number of years, continuing until the ending
year is reached or exceeded, incrementing then number of years each time through the
loop by the specified number of incremental year. For each year selected, display the
number of years, then follow with a table of monthly payments using interest rates
starting at the starting interest rate, continuing until the ending interest rate is met or
exceeded, incrementing the interest rate by the specified incremental interest. The table
will thus contain two labeled columns, interest rate and monthly payment. Refer to
Textbook Example Mortgage.java for soliciting User inputs and performing the monthly
payment calculation.
Sample Run for Problem 2
Enter the loan amount: 275000
Enter the starting number of years to repay the loan: 10
Enter the ending number of years to repay the loan: 20
Enter the years increment between tables: 5
Enter the starting loan yearly interest rate, %: 6.25
Enter the ending loan yearly interest rate, %: 7.25
Enter the increment interest rate, %: 0.5
Principle: $275000.0
Years to repay: 10
Interest Monthly
Rate Payment
-------- -------
6.25 3087.7
6.75 3157.66
7.25 3228.53
Principle: $275000.0
Years to repay: 15
Interest Monthly
Rate Payment
-------- -------
6.25 2357.91
6.75 2433.5
----
Explanation / Answer
import java.util.Scanner;
class chegg
{
public static void main(String args[])
{
double loanAmount,startInterestRate,endInterestRate,incrementInterestRate;
int startyearsToPayLoan,endyearsToPayLoan,yearsBetween;
Scanner input =new Scanner(System.in);
System.out.println("Enter the loan amount:");
loanAmount=input.nextDouble();
System.out.println("Enter the starting number of years to repay the loan:");
startyearsToPayLoan=input.nextInt();
System.out.println("Enter the ending number of years to repay the loan:");
endyearsToPayLoan=input.nextInt();
System.out.println("Enter the years increment between tables:");
yearsBetween=input.nextInt();
System.out.println("Enter the starting loan yearly interest rate, %:");
startInterestRate=input.nextDouble();
System.out.println("Enter the ending loan yearly interest rate, %:");
endInterestRate=input.nextDouble();
System.out.println("Enter the increment interest rate, %:");
incrementInterestRate=input.nextDouble();
double j,monthlyPayment,monthlyRate;
j=startInterestRate;
int monthsBetween;
for(int i=startyearsToPayLoan;i<=endyearsToPayLoan;i=i+yearsBetween)
{
System.out.println();
System.out.println("Principle Amount : "+loanAmount+" $");
System.out.println("years to repay :"+i);
System.out.println("Interest Rate Monthly Payment");
j=startInterestRate;
while(j<=endInterestRate){
monthsBetween=i*12;
monthlyRate=j/(12*100);
monthlyPayment=loanAmount *monthlyRate * Math.pow(1 +(monthlyRate),monthsBetween) /(Math.pow(1 + (monthlyRate), monthsBetween) - 1);
System.out.println(j+" "+(monthlyPayment));
j=j+incrementInterestRate;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.