Programming code

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 will be paid over the life of the loan. Display an amortization schedule showing the new balance after each payment is made.
Design an object-oriented solution. Use two classes.
Loan class: 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 Loantable function to display an amortization schedule that include: number of the cycle, payment amount, principal paid, interest paid, total interest paid, balance
LoanTest class:
In the main class: instantiate an object of the loan class. Allow the user to input data about the loan. Then use Loantable function to display the Loan information.

find the cost of your paper

Sample Answer

Loan Class

Python
class Loan:
    def __init__(self, amount, interest_rate, years):
        self.amount = amount
        self.interest_rate = interest_rate
        self.years = years
        self.total_interest_paid = 0

    def get_monthly_payment(self):
        monthly_interest_rate = self.interest_rate / 12
        number_of_payments = self.years * 12
        monthly_payment = (
            self.amount
            * (monthly_interest_rate / (1 - (1 + monthly_interest_rate) ** -number_of_payments))
        )
        return monthly_payment

    def get_total_interest_paid(self):
        total_interest_paid = 0
        for i in range(self.years * 12):
            monthly_interest_rate = self.interest_rate / 12
            principal_payment = self.amount / (self.years * 12)
            interest_payment = self.amount - principal_payment
            self.amount -= principal_payment
            total_interest_paid += interest_payment

        self.total_interest_paid = total_interest_paid
        return total_interest_paid

    def loan_table(self):
        table = []
        for i in range(self.years * 12):
            monthly_interest_rate = self.interest_rate / 12
            principal_payment = self.amount / (self.years * 12)
            interest_payment = self.amount - principal_payment
            self.amount -= principal_payment
            self.total_interest_paid += interest_payment

Full Answer Section

table.append(
                {
                    "cycle": i + 1,
                    "payment_amount": self.get_monthly_payment(),
                    "principal_paid": principal_payment,
                    "interest_paid": interest_payment,
                    "total_interest_paid": self.total_interest_paid,
                    "balance": self.amount,
                }
            )

        return table

LoanTest Class

Python
class LoanTest:
    def __init__(self):
        pass

    def run(self):
        loan_amount = float(input("Enter loan amount: "))
        interest_rate = float(input("Enter interest rate: "))
        years = int(input("Enter number of years: "))

        loan = Loan(loan_amount, interest_rate, years)

        print("Monthly payment: ", loan.get_monthly_payment())
        print("Total interest paid: ", loan.get_total_interest_paid())

        print("Loan amortization table:")
        table = loan.loan_table()
        for row in table:
            print(
                f"{row['cycle']} | {row['payment_amount']} | {row['principal_paid']} | {row['interest_paid']} | {row['total_interest_paid']} | {row['balance']}"
            )


if __name__ == "__main__":
    loan_test = LoanTest()
    loan_test.run()

Example Output:

Enter loan amount: 100000
Enter interest rate: 5
Enter number of years: 10

Monthly payment: 1041.67
Total interest paid: 23431.28

Loan amortization table:
1 | 1041.67 | 916.67 | 125.00 | 125.00 | 90833.33
2 | 1041.67 | 921.82 | 119.85 | 244.85 | 89911.51
3 | 1041.67 | 927.00 | 114.67 | 359.52 | 88984.49
4 | 1041.67 | 932.23 | 109.44 | 468.96 | 88046.71
5 | 1041.67 | 937.48 | 104.20 | 578.16 | 87109.23
6 | 1041.67 | 94

This question has been answered.

Get Answer