The parameters of the loan are shown in the table below Loan Parameters Loan amo
ID: 3915267 • Letter: T
Question
The parameters of the loan are shown in the table below Loan Parameters Loan amount (the principal) Amount borrowed Interest rate Term Definition Example from the bank 150,000 Interest charged yearly 4% Time duration until the loan is paid back1S years (180 months) The nominal interest rate (eg: 4%) is a yearly interest rate. This rate is divided by 12 to get the monthly interest rate. Therefore, the monthly interest rate is 4/12-0.33%. This means the bank charges 0.33% on the outstanding capital amount each month. For example, for the first month, the outstanding amount is $150,000. Accordingly, the borrower is charged 0.33% * $150,000-S495 In later months, the remaining capital goes down. Let's say after a few years of paying the outstanding capital is $100,000 For that month, the borrower is charged 0.33% * $100,000 = $330 of interest. Accordingly, we can see that the amount of interest paid goes down as the borrower progresses in making the payments. The magic of loan arithmetic is to have the borrower pay a fixed monthly amount over the lifetime of the loan. This amount is derived by the equation below. The term L is the total loan amount. The term m rate is the monthly interest rate (0.33% in our example). The term months is the total loan duration in months (180 months in our example) L {1+m-rate)"months / [ {(1+m-rate)"months) -1 ] * * m-rate Plugging the numbers of our example gives a monthly payment amount of $1,109.33. In the first month, we already computed that the interest payment is S495. Therefore, the remaining ($1,109.53-S495)- S614.53 applies to the loan capital. After this payment is made, the borower owes the bank (S$150,000 $614.53)- $149,385.47 At a later time, let's say the borrower still owes $100,000, we computed above that the interest would be S330. Accordingly, in that month, an amount of (S1,109.53 S330) $77953 is applied to the loan capital. Moving forward, the borrower owes $100,000- $77953-$99,220.47 From these two examples, we can see that the user pays a fixed monthly amount over the lifetime of the loan. However, as the loan payment progresses, the portion applied to interest decreases and the portion applied to the capital increases. The magic of the formula is that the bank keeps charging the interest rate on the outstanding capital each month and the loan is fully paid off by the end of the term while the borrower pays a fixed amount.Explanation / Answer
import java.text.NumberFormat;
import java.util.Scanner;
public class LoanMonthlyPayment {
public static void output_short_format(
double loan_amount,double interest_rate,double term_years) {
// Convert interest rate into a decimal
// eg. 6.5% = 0.065
interest_rate /= 100.0;
// Monthly interest rate
// is the yearly rate divided by 12
double monthlyRate = interest_rate / 12.0;
// The length of the term in months
// is the number of years times 12
double termInMonths = term_years * 12;
// Calculate the monthly payment
// Typically this formula is provided so
// we won't go into the details
// The Math.pow() method is used calculate values raised to a power
double monthlyPayment =
(loan_amount*monthlyRate) /
(1-Math.pow(1+monthlyRate, -termInMonths));
double total_amount=monthlyPayment*12*15;
double total_interest=total_amount-loan_amount;
// Display details of the loan
System.out.println("-----------------------------------------");
System.out.println(" LOAN TERMS");
System.out.println("-----------------------------------------");
System.out.println("Loan Amount: "+loan_amount);
System.out.println("Interest Rate: "+interest_rate*100+" %");
System.out.println("Loan Term: "+term_years+" years");
System.out.println("-----------------------------------------");
System.out.printf(" Monthly Payment: %15.2f",monthlyPayment);
System.out.printf(" Total Interest: %16.2f",total_interest);
System.out.printf(" Total amount paid is : %.2f",total_amount);
}
public static void main(String[] args) {
// Scanner is a great class for getting
// console input from the user
Scanner scanner = new Scanner(System.in);
// Prompt user for details of loan
System.out.print("Enter loan amount: ");
double loan_amount = scanner.nextDouble();
System.out.print("Enter interest rate: ");
double interest_rate = scanner.nextDouble();
System.out.print("Enter loan term (in years): ");
double term_years = scanner.nextDouble();
// Display details of loan
output_short_format(loan_amount, interest_rate,term_years);
}
}
Output
run:
Enter loan amount: 150000
Enter interest rate: 4
Enter loan term (in years): 15
-----------------------------------------
LOAN TERMS
-----------------------------------------
Loan Amount: 150000.0
Interest Rate: 4.0 %
Loan Term: 15.0 years
-----------------------------------------
Monthly Payment: 1109.53
Total Interest: 49715.74
Total amount paid is : 199715.74
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.