Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application that accepts a loan amount, annual interest rate, and loan

ID: 3816811 • Letter: W

Question

Write an application that accepts a loan amount, annual interest rate, and loan period (in number of years) and displays a table with five columns: payment number, the interest and principal paid for that month, the remaining balance after the payment, and the total interest paid to date.

Note: The last payment is generally different from the monthly payment, and your application should print out the correct amount for the last payment. Use a formatter to align the output values neatly.If the input values are invalid, then print out an appropriate error message. Decide on the range of valid values for the loan amount, interest rate, and loan period.

In Java

The monthly payments for a given loan are divided into amounts that apply to the principal and to the interest. For example, if you make a monthly payment of $500, only a portion ofthe $500 goes to the principal and the remainder is the interest payment. The monthly interest is computed by multiplying the monthly interest rate by the unpaid balance. The monthly payment minus the monthly interest is the amount applied to the principal. The following table is the sample loan payment schedule for a one-year loan of S5,000 with a 12 percent annual interest rate. The monthly payment would be $4 44.24 Unpaid Total Interest to Date Payment Principal Interest Balance 4,605.76 394.24 50.00 50.00 398.19 46.06 4,207.57 6.06 3,805.40 402.17 42.08 138.13 38.05 406.19 3,399.21 176.19 2,988.96 410.25 33.99 210.18 240.07 2,574.61 414.35 29.89 265.82 418.50 2,156.11 25.75 422.68 1,733.42 287.38 21.56 426.91 17.33 1,306.51 304.71 875.34 10 431.18 13.07 317.78 439.85 326.53 11 435.49 8.75 12 439.85 4.40 330.93 0.00 Total amount paid 5,330.93

Explanation / Answer

JAVA CODE:


import java.lang.*;
import java.util.*;
import java.io.*;


class Loan

{

// Declare all the required variables.

public static int Months_in_year=12;
public static int FieId_Width=10;

private double loanAmount;
private double interestRate;

private double loanPeriod;

private double monthlyPayment;

private Formatter formatter;

//Create a constructor

public Loan(double loanAmount, double annualRate, int IoanPeriod, double monthlyPayment)

{

this.loanAmount=loanAmount;

this.interestRate=annualRate/Months_in_year;

this.loanPeriod=loanPeriod;
this.monthlyPayment=monthlyPayment;

formatter=new Formatter(System.out);

}

//implement printheader method.

public void printHeader()

{

formatter.format("%"+ FieId_Width*5+"%","Total");
formatter.format("%"+FieId_Width+"%"+FieId_Width*3+"s%" +FieId_Width+"%","Payment","Unpaid","lnterst");
formatter.format("%"+FieId_Width+"s%"+FieId_Width+"s%"+FieId_Width+ "s%"+FieId_Width+"s","No", "interest ","principal", "+Balance","ToDate");

}

//implement printPaymentTable method.

public void printPaymentTabIe()

{
printHeader();

int paymentNumber=0;

double interest;

double principal=0.0;

double unpaidBalance=loanAmount;
double totallnterestPaid=0.0;
while(unpaidBalance>=0.01)

{

paymentNumber++;

interest=interestRate*unpaidBalance;

principal=monthlyPayment-interest;
if(principal>unpaidBalance)

{

principal=unpaidBalance;

}

totallnterestPaid+=interest;

unpaidBalance-=principal;

printPayment(paymentNumber,interest, principal, unpaidBalance,totallnterestPaid);

}

}
public void printPayment(int payNum, double interest, double principal,double unpaidBal,double totlntrPaid)

{

formatter.format("%"+FieId_Width+"d",payNum);
formatter.format("%"+FieId_Width+".2f",interest);
formatter.format("%"+FieId_Width+".2f",principal);
formatter.format("%"+FieId_Width+".2f",unpaidBal);
formatter.format("%"+FieId_Width+".2f",totlntrPaid);
}

public static void main(String args[])

{

//call the constructor.

Loan l=new Loan(100, 5, 12,10);


l.printPaymentTabIe();

}
}

/*Sample output:

Payment No interest Principal Unpaid Total Interest
Balance to Date

1 50.00 394.24 4605.76 50.00

2 46.06 398.19 4207.57 96.06
3 42.08 402.17 3805.40 138.13
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote