Assignment Objective: The assignment aimed to test students’ ability to apply Python programming skills to develop a mortgage calculator that computes repayments and tracks remaining loan balances over time

Assignment 2 Mortgage Calculator

Overview

In this assignment you will have the opportunity to test your Python skills in developing classes and using matplotlib library. Throughout the assignment you are expected to apply the principles of problem solving that we have already discussed in this course.

Learning Outcomes Assessed

The following course learning outcomes are assessed by completing this assessment:

Knowledge:

  • K1. Identify and use the correct syntax of a common programming language.
  • K2. Recall and use typical programming constructs to design and implement simple software solutions.
  • K3. Reproduce and adapt commonly used basic algorithms.
  • K4. Explain the importance of programming style concepts (documentation, mnemonic names, indentation).

Skills:

  • S2. Write and implement a solution algorithm using basic programming constructs.
  • S3. Demonstrate debugging and testing skills whilst writing code.

Application of knowledge and skills:

  • A1. Develop self-reliance and judgement in adapting algorithms to diverse contexts.
  • A2. Design and write program solutions to identified problems using accepted design constructs.

Assessment Details

Introduction

Your assignment is to write a Python program that takes inputs for the Loan Amount, Loan Term and Interest Rate and then calculates and displays values of Weekly (Fortnightly, Monthly) Repayments. Also, the program plots the values of Remaining Principal by years.

Programming Tasks

Task 1.1 Develop a Mortgage class

The class should have the following attributes (instance variables):

  • loan – for the loan amount in AUD.
  • years – loan term in years.
  • interest – interest rate.
  • r_frequency – repayment frequency in days.

These attributes should be defined in the constructor, _init_ . Also, the class should define the following methods:

  • repayments(self) – calculates the value of repayments using the formula provided in the introduction (for P0) and returns the calculated value.
  • balance_after(self,n) – calculates the remaining balance (debt) after n years using the formula provided in the introduction (for Bn) and returns the calculated value.

Task 1.2 Write a main() function

This should be your main program that:

  • Prompts and takes inputs for the loan amount, loan term, interest rate and repayment frequency. 
  • Creates a Mortgage object using the entered values. 
  • Using the Mortgage object’s methods, prints the mortgage information on screen and, and if required, plots the mortgage balances by years.

You are required to use exception handling to make your program robust (foolproof) i.e., if the user enters an incorrect value, the program won’t crash, but instead it will prompt the user to enter a correct value. Use the following constraints for the correct inputs:

  • loan – must be a positive float value.
  • years – must be a positive int value.
  • interest – must be a positive float value.
  • r_frequency – must be one of the following values: 7, 14, or 30.

Assessment Requirements  Brief Summary

Assignment Objective:
The assignment aimed to test students’ ability to apply Python programming skills to develop a mortgage calculator that computes repayments and tracks remaining loan balances over time. Students were expected to use object-oriented programming, handle exceptions, and generate visual outputs using the matplotlib library.

Key Pointers to Cover:

  1. Mortgage Class Development (Task 1.1)
    • Attributes: loan, years, interest, r_frequency
    • Methods:
      • repayments(self) – Calculate repayment amount based on input parameters
      • balance_after(self, n)– Calculate remaining principal after n years
  2. Main Program Function (Task 1.2)
    • Prompt user inputs for loan amount, loan term, interest rate, and repayment frequency
    • Create a Mortgage object
    • Print mortgage details and plot remaining balances over the years
    • Implement exception handling for input validation:
      • Loan: positive float
      • Years: positive integer
      • Interest: positive float
      • Repayment frequency: 7, 14, or 30

Learning Outcomes Assessed:

  • Knowledge of Python syntax and programming constructs (K1-K4)
  • Practical coding skills, algorithm implementation, debugging, and testing (S2-S3)
  • Application of knowledge to develop problem-solving solutions (A1-A2)

Step-by-Step Approach by the Academic Mentor

    • Guided the student to define the Mortgage class with proper constructor and instance variables.
    • Emphasized code readability, use of mnemonic names, and proper documentation.
    • repayments(self) method: Mentor walked through the repayment formula and helped implement it in Python.
    • balance_after(self, n) method: Mentor explained how to calculate remaining principal after n years, integrating it into the class for reuse.
    • Mentor instructed the student to collect user inputs and validate them using exception handling to prevent crashes.
    • Demonstrated how to instantiate the Mortgage class and call its methods to display outputs.
    • Guided the student on using matplotlib to plot remaining balances over the loan period.
    • The student was guided through multiple test cases with valid and invalid inputs to ensure robustness.
    • Mentor reviewed edge cases such as zero or negative values and incorrect repayment frequency entries.
    • Mentor ensured that the outputs were correct and aligned with assignment requirements.
    • Checked for proper formatting, readability, and code commenting.

    Final Review and Output:

    Testing and Debugging:

    Developing the Main Function:

    Implementing Methods:

    Designing the Class Structure:

    Understanding the Assignment:

    The mentor first reviewed the requirements and clarified the expected outputs – repayment calculations, remaining balance computations, and visual representation.

    Outcome Achieved

    • Functional Mortgage Calculator: Program accurately computes weekly, fortnightly, and monthly repayments and visualizes remaining balances over the loan term.
    • Robustness: Exception handling ensures that the program prompts for correct inputs rather than crashing.
    • Code Quality: Clear, well-documented Python code following good programming style.
    • Learning Objectives Covered:
      • Applied object-oriented programming concepts (K1, S2)
      • Developed algorithmic thinking and debugging skills (S3, A2)
      • Built a self-reliant, functional software solution (A1)
      • Integrated data visualization with matplotlib

    Access Your Assignment Reference Today or Get a Fresh, Custom Solution

    Looking for guidance on your assignment? You can download our sample solution to understand how a well-structured answer looks and how to approach similar questions.

    Similar Posts