Question

CIS 221 Loan Calculator Enhancement Introduction You are a systems analyst working for a company that...

CIS 221 Loan Calculator Enhancement

Introduction

You are a systems analyst working for a company that provides loans to customers. Your manager has asked you to enhance and correct their existing Loan Calculator program, which is designed to calculate monthly and total payments given the loan amount, the annual interest rate, and the duration of the loan. Although the current version of the program (hereby termed the “As Is” version) has some functionality, there are several missing pieces, and the user would like to see significant improvements. Also, the program has some bugs that need to be fixed. After a requirements elicitation session (see https://en.wikipedia.org/wiki/Requirements_elicitation), you have uncovered the following facts about the As Is version, and you are prepared to work with this existing program and create the enhanced version (hereby termed the To Be version).

Note: the as-is program is Listing 9.11 LoanCalculator.py, which is described in section 9.7 of the textbook. The existing code is available in the Ch9 examples, which you can download from Canvas.

The requirements are discussed below.

The As Is System

In its current state, the program takes user input in the form of an annual interest rate, number of years, and total loan amount. It displays the calculated monthly payment, and the calculated total payment. This image shows an example.

This is fine as far as it goes. But it has a glitch. For example, if the user fails to enter proper numeric values, the program aborts with an ugly message like this:

Users are very annoyed when they see this, and they have to restart the program in order to continue their work.

Also, the program is incomplete. There is more functionality that the users want, which is described below.

The To Be System


The users would like additional functionality to the program, and also some corrections.

First, your program should handle exceptions more gracefully. Rather than the ugly situation described above, an error message should appear telling the user what correction to make. For example, if the user clicks the calculate button without having proper input data entered, you should display a dialog like this:

Second, the program should include an amortization schedule. This should be displayed in a Text widget. This screens shows an example of what would appear given user input:

Note also that the interest, monthly payment, and total payment values are shown in nice currency format. In order to make these amounts show up with good currency format, you can make use of Python’s locale module: https://docs.python.org/2/library/locale.html. Use Google to find out how you can do this.

Finally, we want to be able to save the loan report to a file (note the extra button in the above figure). If the user wants to do this, you should prompt the user to enter the loan recipient’s name using a dialog, as shown below:

When the user enters the name, you should write to a file named based on the entered name. This should include data shown as below:

In addition to the proper functioning program, please also include a modified UML diagram. The original UML diagram is included in the PowerPoints for Ch9. The modified UML diagram will include any additional methods you wrote to accomplish your programming task.

Final Deliverables:

Upload the modified Python program and the modified UML diagram to Canvas.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of the code:

#Import the required packages. from tkinter import* import tkinter.messagebox import tkinter. simpledialog #Define the class#Declare a button to calculate payment btn cal_pay - Button (window, text -Compute Payment, command - self.caloulatepay) grPrompt the user to enter the name of loan Recipient fname - tkinter.simpledialog.askstring ( Loan Recipient , Enter the natGet the principal amount by subtracting interest rate from monthly interest and multiply and divide the value by 10 pri_amt#Define the method get mon pay() def get mon pay (self, loan, month int rate, num years): #Calculate the montly payment payof

Sample Output:

Loan Calculator Annual Interest Rate Number of Years Loan Amount Monthly Payment Total Payment Compute PaymentSave load to FiLoan Calculator Annual Interest Rate Number of Years Loan Amount Monthly Payment Total Payment Compute PaymentSave load to Fi84520970901177800656 28670410913693726924 69084663686133933056 12445555432197429628 62840628406273950627 99888776665544333221Loan Calculator Annual Interest Rate「 Number of Years 8.5 oan Amo Loan Recipient Monthly P Total Payr Enter the name of loanAlexendarloan document.tt - Notepad File Edit Format View Help Loan Document for Alexendar Loan Amount : $100000.0 Interest R

Code to copy:

#Import the required packages.

from tkinter import *

import tkinter.messagebox

import tkinter.simpledialog

#Define the class LoanCalculator.

class LoanCalculator:

#Define the constructor of the class.

def __init__(self):

     

    #Create a window.

    window = Tk() # Create a window

       

    #Set the title of the window.

    window.title("Loan Calculator") # Set title

     

    #Set the orientation of window.

    window.geometry('{}x{}'.format(400, 150))

   

    #Create a label for the interest rate.

    Label(window, text = "Annual Interest Rate").grid(row = 1, column = 1,sticky = W)

           

    #Create a label for the number of years.   

    Label(window, text = "Number of Years").grid(row = 2, column = 1, sticky = W)

           

    #Create a label for the loan amount.

    Label(window, text = "Loan Amount").grid(row = 3, column = 1, sticky = W)

           

    #Create a label for the monthly interest.   

    Label(window, text = "Monthly Payment").grid(row = 4, column = 1, sticky = W)

           

    #Create a label for the total payment.   

    Label(window, text = "Total Payment").grid(row = 5, column = 1, sticky = W)

     

    #Prompt the user to enter the annual interest rate.

    self.ann_int_rate = StringVar()

    Entry(window, textvariable = self.ann_int_rate, justify = RIGHT).grid(row = 1, column = 2)

    #Prompt the user to enter the number of years.

    self.no_of_years = StringVar()

    Entry(window, textvariable = self.no_of_years, justify = RIGHT).grid(row = 2, column = 2)

    #Prompt the user to enter the loan amount.

    self.loan_amt = StringVar()

    Entry(window, textvariable = self.loan_amt, justify = RIGHT).grid(row = 3, column = 2)

   

    #Declare a label to store the monthly payment.

    self.monthly_pay = StringVar()

    label_mon_pay = Label(window, textvariable = self.monthly_pay).grid(row = 4, column = 2, sticky = E)

   

    #Declare a label to store the total payment.

    self.tot_pay = StringVar()

    lblTotalPayment = Label(window, textvariable = self.tot_pay).grid(row = 5, column = 2, sticky = E)

   

    #Declare a button to calculate payment.

    btn_cal_pay = Button(window, text = "Compute Payment", command = self.calculate_pay).grid(row = 7 , column = 1, sticky = E)

   

    #Declare a button to load a file.

    btn_save_file = Button(window, text = "Save load to File", command = self.display_Shedule).grid(row = 7 , column = 2, sticky = E)

     

    # Create a main loop.

    window.mainloop() # Create an event loop

#Define the method calculate_pay().

def calculate_pay(self):

   

    #Check if the interest rate, loan amount, number of years is not a digit, then show an error.

    if (self.ann_int_rate.get().replace('.','',1).isdigit() == False

    or self.loan_amt.get().replace('.','',1).isdigit() == False

    or self.no_of_years.get().replace('.','',1).isdigit() == False):

      tkinter.messagebox.showerror("Calculation Error", "Please make sure to enter numeric values for interest rate, years, and\nloan amount")

    return

     

    #Store the returned value of the method get_mon_pay() into variable mon_pay.

    mon_pay = self.get_mon_pay(

    float(self.loan_amt.get()),

    float(self.ann_int_rate.get()) / 1200,

    int(self.no_of_years.get()))

     

    #Set the monthly payment.

    self.monthly_pay.set(format(mon_pay, '1.2f'))

     

    #Calculate the total payment.

    sum_pay = float(self.monthly_pay.get()) * 12 \

            * int(self.no_of_years.get())

     

    #Set the value of total payment variable.

    self.tot_pay.set(format(sum_pay, '1.2f'))

     

    #Call the function amort_Sched().

    self.amort_Sched(

    float(self.loan_amt.get()),

    float(self.ann_int_rate.get()) / 1200,

    int(self.no_of_years.get()))

#Define the method display_Shedule().

def display_Shedule(self):

   

    #Check if the interest rate, loan amount, number of years is not a digit, then show an error.

    if ( self.ann_int_rate.get().replace('.','',1).isdigit() == False

    or self.loan_amt.get().replace('.','',1).isdigit() == False

    or self.no_of_years.get().replace('.','',1).isdigit() == False):

      tkinter.messagebox.showerror("Calculation Error", "Please make sure to enter numeric values for interest rate, years, and\nloan amount")

   

    return

   

    #Prompt the user to enter the name of loan Recipient.

    fname = tkinter.simpledialog.askstring(

    "Loan Recipient ", "Enter the name of loan recipient")

   

    #Call the function printToFile().

    self.printToFile(fname,

    float(self.loan_amt.get()),

    float(self.ann_int_rate.get()) / 1200,

    int(self.no_of_years.get()))

#Define the method printToFile().

def printToFile(self,fname, loan, mon_int, num_years):

   

    #Append the loan document.txt with the name of the file.

    fi_Name = fname + "loan document.txt"

   

    #Open the output file in write mode.

    outfile = open(fi_Name, 'w')

   

    #Store the header of the file.

    headOfFile = "\t\t\t Loan Document for " + fname + "\n\t\t\t-------------------------------"

   

    #Display the header to the file.

    outfile.write(headOfFile)

   

    #Store the required fields of first line.

    first_line = "\n\nLoan Amount: $" + str(loan) + "\tInterest Rate: " + str(self.ann_int_rate.get()) + "%\t\tNbr Years: " + str(num_years) + "\n"

   

    #Display the first line to the file.

    outfile.write(first_line)

   

    #Get the second line of the file.

    sec_line = "Monthly Payment: $" + str(self.monthly_pay.get()) + "\t\tTotal Payment: $" + str(self.tot_pay.get()) + "\n"

   

    #Display the line to the file.

    outfile.write(sec_line)

   

    #Get the third line.

    thi_line = "\n\nAmortization    Schedule\npmt#\t\tinterest\t\tprin pmt\t\tremianing prin\n"

   

    #Display this line to the file.

    outfile.write(thi_line)

   

    #Start a for loop till num_years*12 + 1.

    for i in range(1, num_years * 12 + 1):

     

      #Get the interest rate by multiplying monthly interest by loan amount and 10 and divide by 10.

      int_rate = int(mon_int * loan * 10) / 10.0

     

      #Get the principal amount by subtracting interest rate from monthly interest and multiply and divide the value by 10.

      pri_amt = int((float(self.monthly_pay.get()) - int_rate) * 10) / 10.0

     

      #Get the loan amount.

      loan = int((loan - pri_amt) * 10) / 10.0

     

      #Get the resulted line.

      res = (str(i) + "\t\t\t$" + str(int_rate) + "\t\t\t$" + str(pri_amt) + "\t\t\t\t$" + str(loan) + "\n")

     

      #Write the resulted line to the file.

      outfile.write(res)

     

      #Close the file.

      outfile.close()

#Define the method amort_Sched().

def amort_Sched(self, amt_loan, month_int_rate, num_years):

   

    #Create another window.

    window = Tk()

   

    #Set the title of the window.

    window.title("Amortization Schedule")

   

    #Add text to the window.

    txt = Text(window) # Create and add text to the window

    txt.pack()

     

    #Declare the header line.

    line = "\n\nAmortization    Schedule\npmt#\t\tinterest\t\tprin pmt\t\tremianing prin\n"

   

    #Insert this line into the text.

    txt.insert(END, line)

   

    #Start the for loop.

    for i in range(1, num_years * 12 + 1):

     

      #Get the value of interest rate.

      int_rate = int(month_int_rate * amt_loan * 10) / 10.0

     

      #Get the principal amount.

      prin_amt = int((float(self.monthly_pay.get()) - int_rate) * 10) / 10.0

     

      #Get the amount of the loan.

      amt_loan = int((amt_loan - prin_amt) * 10) / 10.0

     

      #Get the resulted value.

      res = (str(i) + "\t\t$" + str(int_rate) + "\t\t$" + str(prin_amt) + "\t\t$" + str(amt_loan) + "\n")

     

      #Insert the resulted value to the text.

      txt.insert(END, res)

     

#Define the method get_mon_pay().

def get_mon_pay(self, loan, month_int_rate, num_years):

   

    #Calculate the montly payment.

    payOfMonth = loan * month_int_rate / (1 - 1 / (1 + month_int_rate) ** (num_years * 12))

   

    #Return the value of monthly payment.

    return payOfMonth;

#Call the LoanCalculator() class to create the required GUI.

LoanCalculator()

The UML diagram for the LoanCalculator class is shown as follows:

LoanCalculator

loan_amt : int

ann_int_rate : float

no_of_years : int

mon_pay : float

tot_pay : float

mon_int_rate : float

calculate_pay() : void

display_Shedule() : void

printToFile(fname, loan, mon_int, num_years) : void

amort_Sched(amt_loan, month_int_rate, num_years) : void

get_mon_pay(loan, month_int_rate, num_years) : float

The name of the class is LoanCalculator. The class LoanCalculator has 6 attributes which are as follows:

·       loan_amt

·       ann_int_rate

·       no_of_years

·       mon_pay

·       tot_pay

·       mon_int_rate

The class LoanCalculator has 5 methods which are as follows:

·       calculate_pay(): This method is used to calculate the total payment and monthly payment.

·       display_Shedule(): This method is used to display the whole schedule of loan amount calculations.

·       printToFile(fname, loan, mon_int, num_years): This method is used to print the whole schedule of loan calculations on an output file.

·       amort_Sched(amt_loan, month_int_rate, num_years): This method is used for the amortization of the schedule of loan calculations and wrap the required lines in the text.

·       get_mon_pay(loan, month_int_rate, num_years): This method is used to calculate and return the monthly payment.

Add a comment
Know the answer?
Add Answer to:
CIS 221 Loan Calculator Enhancement Introduction You are a systems analyst working for a company that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay-...

    MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay- ments based on compound interest formulas The program should prompt a user to input the amount borrowed (principal), p, the number of monthly payments, n, and an annual interest rate in R percent. The program should convert the annual interest rate R into a monthly interest rate...

  • My library>CptS 111 home> 2.9: zyLab PA #1: Student Loan R oks zyBooks cat @Help/FAQ θ...

    My library>CptS 111 home> 2.9: zyLab PA #1: Student Loan R oks zyBooks cat @Help/FAQ θ Mohammed Al Shukaili 2.9 zyLabPA#1:Student Loan RepaymentCalculator For this assignment you wil write a program to calculate the monthly payments required to pay back a student loan You vill need to prompt the user for the following values Annual interest rate (as a percentage) Number of years to repay loan . and display the output in a readable form. Output should include Amount of...

  • Hi, the language is Java. Learning Outcomes and Introduction In this lab assignment you will practice:...

    Hi, the language is Java. Learning Outcomes and Introduction In this lab assignment you will practice: . applying access modifiers using getters and setters to mediate access using getters and setters to create derived attributes using static variables and methods testing code using a unit testing approach . For each of the tasks in this lab, you will create a new class or create an improved version of one of the classes from the previous lab. Remember to document all...

  • You are working as a software developer for a large insurance company. Your company is planning...

    You are working as a software developer for a large insurance company. Your company is planning to migrate the existing systems from Visual Basic to Java and this will require new calculations. You will be creating a program that calculates the insurance payment category based on the BMI score. Your Java program should perform the following things: Take the input from the user about the patient name, weight, birthdate, and height. Calculate Body Mass Index. Display person name and BMI...

  • THE PROBLEM: The nice folks from the Lion Lending Company have hired you to write some...

    THE PROBLEM: The nice folks from the Lion Lending Company have hired you to write some software that will process their daily loan information. The data will come from a text file that has the following format: The first line will contain an integer: number of loan applications There will be two rows for each of the customers First line will be the customer's (1) first name and (2) last name, separated by a space (assume there is no spaces...

  • C++ Program - Loan Payment Report Please write a C++ program to generate a detail loan payment report from the first month until the loan balance becomes zero or less than ten cents. You may use a whi...

    C++ Program - Loan Payment Report Please write a C++ program to generate a detail loan payment report from the first month until the loan balance becomes zero or less than ten cents. You may use a while loop such as: while (loanBalance >= monthPayment) { … }. When the loanBalance is less than the monthPayment, you need to compute the final payment amount, which should be the loanBalance plus its interest of one month. For example, if your last-month’s...

  • Ensure our user enters a positive starting loan amount. (Page 186-7 is a good inspiration) ....

    Ensure our user enters a positive starting loan amount. (Page 186-7 is a good inspiration) . Try $0 Try a negative amount (like $-400) Conclude with the proper amount ($10,000) Create a program flowchart, using the software of your choice, to communicate the program logic for your solution. Insert the diagram below. (Remember, you can use https://formswift.com/flow-chart to create these diagrams) Output should look like this ... What is your name? Grant What is your starting loan amount? ($10,000 would...

  • This C++ Program should be written in visual studio 2017 You are to write a program...

    This C++ Program should be written in visual studio 2017 You are to write a program that can do two things: it will help users see how long it will take to achieve a certain investment goal given an annual investment amount and an annual rate of return; also, it will help them see how long it will take to pay off a loan given a principal amount, an annual payment amount and an annual interest rate. When the user...

  • Option 1: Authentication System For security-minded professionals, it is important that only the appropriate people gain...

    Option 1: Authentication System For security-minded professionals, it is important that only the appropriate people gain access to data in a computer system. This is called authentication. Once users gain entry, it is also important that they only see data related to their role in a computer system. This is called authorization. For the zoo, you will develop an authentication system that manages both authentication and authorization. You have been given a credentials file that contains credential information for authorized...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT