1-Create an application that will allow a loan amount, interest rate, and number
ID: 3854534 • Letter: 1
Question
1-Create an application that will allow a loan amount, interest rate, and number of finance years to be entered for a given loan. Determine the monthly payment amount. Calculate how much interest be paid over the loan. Display an amortization schedule showing the new balance after each payment is made. anthatte allow emanamount intenamtrum 2 Design an object-oriented solution by using the three layers architecture. For the load dlass, characteristics such as the amount to be financed, rate of interest period of time for the loan, and total interest paid will identify the current state of a loan object. Include methods to determine the monthly payment amount, return the total interest paid over the life of the loan, and return an amontization schedule. In the second class, instantiate an object of the load class. Allow the user to input data about more than one loan. Display in the loan LoanApp class the payment amount, amortization schedule, and the total amount of interest to be paid. In the third class, provides a discount percent based on payment amount paid Note: Test for valid data entries. Formulas are needed to calculate the following: numPayments years * 12; term·(1+ rate /12»--m // javalangMath // For example: double result-Math.pow(22k result is 40 (2"2) paymentAmount loanAmount rate/12 term/(term-1.O) monthinterest rate/12*balance Principal payment-monthinterest Balance- balance- principal Tot Discount Amount- paymentAmount discountPercent Note: The desired output is to display the monthly payment amount, an amortization schedule, and the total interest paid over the life of the loan. The following shows a prototype for the final output.Explanation / Answer
Loan.cs
/* Loan.cs
* Creates fields for
* the amount of loan, interest
* rate and number of years.
* Calculates amount of payment
* and produces an amortization
* schedule
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LoanApp
{
class Loan
{
private double loanAmount;
private double rate;
private int numPayments;
private double balance;
private double totalInterestPaid;
private double paymentAmount;
private double principal;
private double monthInterest;
// Default constructor
public Loan()
{
}
// Constructor
public Loan(double loan, double interestRate,
int years)
{
loanAmount = loan;
if (interestRate < 1)
rate = interestRate;
else //In case directions aren't followed
rate = interestRate / 100; // convert to decimal
numPayments = 12 * years;
totalInterestPaid = 0;
DeterminePaymentAmount();
}
// Property accessing payment amount
public double PaymentAmount
{
get
{
return paymentAmount;
}
}
// Property setting and returning
// loan amount
public double LoanAmount
{
set
{
loanAmount = value;
}
get
{
return loanAmount;
}
}
// Property setting and returning rate
public double Rate
{
set
{
rate = value;
}
get
{
return rate;
}
}
// Property to set the numPayments,
// given years to finance.
// Returns the number of years using
// number of payments.
public int Years
{
set
{
numPayments = value * 12;
}
get
{
return numPayments / 12;
}
}
// Property for accessing
// total interest to be paid
public double TotalInterestPaid
{
get
{
return totalInterestPaid;
}
}
// Determine payment amount based on
// number of years, loan amount and rate
public void DeterminePaymentAmount()
{
double term;
term = Math.Pow((1 + rate / 12.0),
numPayments);
paymentAmount = (loanAmount * rate /
12.0 * term) / (term - 1.0);
}
// Returns a string containing an
// amortization table
public string ReturnAmortizationSchedule()
{
string aSchedule = "Month Int. Prin. New";
aSchedule += " No. Pd. Pd. Balance ";
aSchedule += "------- ------- -------- ---------- ";
balance = loanAmount;
for (int month = 1; month <= numPayments; month++)
{
CalculateMonthCharges(month, numPayments);
aSchedule += month
+ " "
+ monthInterest.ToString("N2")
+ " "
+ principal.ToString("N2")
+ " "
+ balance.ToString("C")
+ " ";
}
return aSchedule;
}
// Calculates monthly interest,
// applied principal and new balance
public void CalculateMonthCharges(int month,
int numPayments)
{
double payment = paymentAmount;
monthInterest = rate / 12 * balance;
if (month == numPayments)
{
principal = balance;
payment = balance + monthInterest;
}
else
{
principal = payment - monthInterest;
}
balance -= principal;
}
// Calculates the amount of interest paid
// over the life of the loan
public void DetermineTotalInterestPaid()
{
totalInterestPaid = 0;
balance = loanAmount;
for (int month = 1; month <= numPayments; month++)
{
CalculateMonthCharges(month, numPayments);
totalInterestPaid += monthInterest;
}
}
//Return information about the loan
public override string ToString()
{
return " Loan Amount: " + loanAmount.ToString("C") +
" Interest Rate: " + rate +
" Number of Years for Loan: " + (numPayments / 12) +
" Monthly payment: " + paymentAmount.ToString("C");
}
}
}
LoanApp.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LoanApp
{
class LoanApp
{
static void Main(string[] args)
{
int years;
double loanAmount;
double interestRate;
string inValue;
char anotherLoan = 'N';
do
{
GetInputValues(out loanAmount, out interestRate,
out years);
Loan ln = new Loan(loanAmount, interestRate, years);
Console.WriteLine();
Console.Clear();
Console.WriteLine(ln);
Console.WriteLine( );
Console.WriteLine(ln.ReturnAmortizationSchedule());
ln.DetermineTotalInterestPaid();
Console.WriteLine("Payment Amount: {0:C}", ln.PaymentAmount);
Console.WriteLine("Interest Paid over Life of Loan: {0:C}",
ln.TotalInterestPaid);
Console.Write("Do another Calculation? (Y or N)");
inValue = Console.ReadLine();
anotherLoan = Convert.ToChar(inValue);
}
while ((anotherLoan == 'Y') || (anotherLoan == 'y'));
}
// Prompts user for loan data
public static void GetInputValues(out double loanAmount,
out double interestRate,
out int years)
{
Console.Clear( );
loanAmount = GetLoanAmount();
interestRate = GetInterestRate();
years = GetYears();
}
public static double GetLoanAmount()
{
string sValue;
double loanAmount;
Console.Write("Please enter the loan amount: ");
sValue = Console.ReadLine();
while (double.TryParse(sValue, out loanAmount) == false)
{
Console.WriteLine("Invalid data entered " +
"for loan amount");
Console.Write(" Please re-enter the loan amount: ");
sValue = Console.ReadLine();
}
return loanAmount;
}
public static double GetInterestRate()
{
string sValue;
double interestRate;
Console.Write("Please enter Interest Rate (as a decimal value " +
"- i.e. .06): ");
sValue = Console.ReadLine();
while (double.TryParse(sValue, out interestRate) == false)
{
Console.Write(" Invalid data entered " +
"for loan amount");
Console.Write(" Please re-enter the interest rate: ");
sValue = Console.ReadLine();
}
return interestRate;
}
public static int GetYears()
{
string sValue;
int years;
Console.Write("Please enter the number of Years for the loan: ");
sValue = Console.ReadLine();
while (int.TryParse(sValue, out years) == false)
{
Console.Write(" Invalid data entered " +
"for years");
Console.Write(" Please re-enter the years: ");
sValue = Console.ReadLine();
}
return years;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.