please help with code for this assignment
CMPS 5P Homework 5 Spring 19 1 Instructions 1. The aim of this assignment is to practice creating, initializing and using python classes from input data. 2. The deadline for the assignment is 06/02/2019 (Monday) 11:59 PM. 3. The grade of the assignment is out of 100 pts. 4. Students must use Python3. 5. Don’t share code or get code from the internet, but working together is encouraged. If you choose to work with someone you must mention them in one of the first comments in the file. 6. Students are expected to write the code that is easily readable. To this end, they must employ meaningful variable names and comment their code properly. 7. The output of the code requires to be precisely as shown in the sample runs. 8. Students must put the code in a file named FirstName LastName StudentID HW5.py and submit it through Canvas. Please notice that failing to comply any of these re- quirements will result in losing points at the discretion of the grader. Grading The assignment is out of 100 points. It is important that you practice commenting your code, so each file submitted without comments will have 5 points deducted from its score (even if the program works perfectly)! Furthermore, the formatting of the the file names (described in item 8) is important for us to grade all 240 assignments, so submissions which are not named in this way will have 5 points deducted from their overall score. Assignment 5 In this assignment you will be creating 4 classes Loan, Client, Accountant, and Bank along with a single function called create banks from file. 1.1 Loan The Loan class takes in 3 arguments principal, rate, and time each of which will be floats or ints. Each argument needs to become a instance variable named self.principal, self.rate, and self.time. You need to implement 3 methods. 1 CMPS 5P Homework 5 Spring 19 1.1.1 calculate monthly payment The basic idea of the Loan class is that it can calculate some information regarding loans. calculate monthly payment calculates the amount one needs to pay per month to pay back the loan in the correct amount of time. The total amount borrowed money is the principal, the number of payments is time and the interest rate per month is rate. In order to calculate the total cost per month you need to use the equation 6. If you are interested or confused, you can see where I got the equation and a deeper explanation here P = principal (1) r = rate (2) t = time (3) A = cost per month (4) (5) A = P r(1 + r)t (1 + r)t − 1 (6) 1.1.2 calculate total owed calculate total owed needs to calculate the total amount of the loan which needs to be paid. This is the time multiplied by the cost per month. 1.1.3 calculate total interest calculate total interest needs to calculate the total amount of interest which will be paid. This is the total owed minus the principal 1.2 Client The Client class takes in 4 arguments name, total savings, total checking, and loan. name will be a string and both total savings and total checking will be floats or ints. loan is supposed to be an instantiated Loan object. You need to implement 5 methods. 1.2.1 total in checking Return total checking. 1.2.2 total in savings Return total savings. 2 https://www.vertex42.com/ExcelArticles/amortization-calculation.html http://openbookproject.net/thinkcs/python/english3e/classes_and_objects_I.html CMPS 5P Homework 5 Spring 19 1.2.3 total borrowed Return the amount of money borrowed. This can be found out through the Loan object passed in via loan. 1.2.4 total interest Return the amount of interest owed. This can be found out through the Loan object passed in via loan. 1.2.5 total owed Return total amount of money owed. This can be found out through the Loan object passed in via loan. 1.3 Accountant The Accountant class takes in 1 argument, name (a string). You need to implement 5 methods. 1.3.1 add client This method takes in a Client object and adds it to self.clients. It does not need to return anything 1.3.2 get client This method takes in a name and searches for the client in self.clients. If the client exists, return the client otherwise return None. 1.3.3 get number of clients This method returns the number of clients this Accountant has. 1.3.4 total in checking Returns the sum total amount in all the clients’ checking accounts. 1.3.5 total in savings Returns the sum total amount in all the clients’ savings accounts. 3 CMPS 5P Homework 5 Spring 19 1.3.6 total loaned out Returns the sum total amount loaned out to the clients. 1.3.7 calculate total profit Returns the sum total amount of interest that the clients have to pay. This is considered ”profit” since the bank makes money off of loans by collecting interest. 1.4 Bank The Bank class takes in 1 argument, name (a string). You need to implement 8 methods. 1.4.1 add accountant This method takes in a Accountant object and adds it to self.accountants. It does not need to return anything 1.4.2 get accountants This method takes in a name and searches for the client in self.accountant. If the accoun- tant exists, return the accountant otherwise return None. 1.4.3 get number of accountants This method returns the number of accountants this Bank has. 1.4.4 total in checking Returns the sum total amount in all the accountants’ clients’ checking accounts. 1.4.5 total in savings Returns the sum total amount in all the accountants’ clients’ savings accounts. 1.4.6 total loaned out Returns the sum total amount loaned out to all accountants’ clients. 4 CMPS 5P Homework 5 Spring 19 1.4.7 calculate total profit Returns the sum total amount of interest that the accountants’ clients have to pay. 1.5 create banks from file create banks from file is a stand alone function which will be parsing a csv (comma- separated values) file and converting the data in the csv file into Bank, Accountant, Client and Loan classes you just created. You will be given two test csv files [banking statement.csv, banking statement2.csv ]. Each of these files contains a header and some data. banking statement.csv: Bank,Accountant,Client,Savings,Checking,Principal,Rate,Time boa,acct1,client1,1000,2000,100,0.1,10 boa,acct1,client2,1000,2000,100,0.1,20 banking statement2.csv : Bank,Accountant,Client,Savings,Checking,Principal,Rate,Time boa,acct1,client1,1000,2000,100,0.1,10 chase,acct1,client3,1000,2000,0,0,0 boa,acct2,client2,1000,2000,20,0.1,10 chase,acct1,client1,1000,2000,0,0,0 boa,acct2,client3,1000,2000,10,0.1,20 chase,acct1,client2,1000,2000,0,0,0 If we look at the first file, banking statement.csv, you can see that this function will create two Loans, one for each Client. Both clients are with a single Accountant which works for a single Bank. Therefore, you will return a list of length 1 with a single Bank object. You can assume that each line has a unique combination of bank, accountant, and client so there are no rows with the same client, accountant and bank. However, that does not mean the names can be reused in other orderings as you can see from banking statement2.csv. IMPORTANT NOTE!: The main function has almost all tests you need to pass. Once you put the correct paths to banking statement.csv and banking statement2.csv in the main, do not change it! You should work on getting each assert statement to pass. If you can run the main and there are no errors you are guaranteed an A. 5 CMPS 5P Homework 5 Spring 19 2 Skeleton code A good idea to get started on your assignment is to reproduce the code below in your favourite code editor and start filling up the functions. #!/usr/bin/env python class Bank(object): """Keeps track of number of accountants, clients, and bank accounts""" def __init__(self, name): self.name = name self.accountants = [] def add_accountant(self, accountant): """Add an accounted to list of accountants""" pass def get_accountant(self, accountant_name): """Get an accountant from list of accountants via their name""" pass def get_number_of_accountants(self): """Calculate the number of accountants the bank has""" pass def get_number_of_clients(self): """Calculate the number of clients the bank has""" pass def total_in_checking(self): """Calculate total amount of money in checking from all clients from all accountants combined""" pass def total_in_savings(self): """Calculate total amount of money in savings from all clients from all accountants combined""" pass def total_loaned_out(self): """Calculate total amount of money loaned out from all clients from all accountants combined""" pass 6 CMPS 5P Homework 5 Spring 19 def calculate_total_profit(self): """Calculate total amount of profit from all accountants combined""" pass class Accountant(object): """Keep track of clients for an accountant""" def __init__(self, name): self.name = name self.clients = [] def add_client(self, client): """Add a client object to list of clients""" pass def get_client(self, client_name): """Get a client from list of clients via it's name""" pass def get_number_of_clients(self): """Calculate the number of clients the accountant has""" pass def total_in_checking(self): """Calculate total amount of money in checking from all clients combined""" pass def total_in_savings(self): """Calculate total amount of money in savings from all clients combined""" pass def total_loaned_out(self): """Calculate total amount of money loaned out from all clients combined""" pass def calculate_total_profit(self): """Calculate total amount of interest from all clients combined""" pass class Client(object): 7 CMPS 5P Homework 5 Spring 19 """Keep track of clients for an accountant""" def __init__(self, name, total_savings, total_checking, loan): self.name = name self.total_savings = total_savings self.total_checking = total_checking self.loan = loan def total_in_checking(self): """Return total amount in checking""" pass def total_in_savings(self): """Return total amount in savings""" pass def total_borrowed(self): """Return amount of money borrowed""" pass def total_interest(self): """Return the amount of interest needed to pay""" pass def total_owed(self): """Return total amount of money needed to pay""" pass def create_banks_from_file(input_csv): """Given an input csv file, create a list of banks with all Loans, Clients and Accountants correctly formed :param input_csv: path to input csv file :return: list of Bank objects """ pass def main(): """Tests""" ############################################################################################# # TODO put correct paths to both files banking_file1 = "banking_statement.csv" 8 CMPS 5P Homework 5 Spring 19 banking_file2 = "banking_statement2.csv" ############################################################################################# # DO NOT CHANGE ANYTHING BELOW HERE # Testing Loan loan1 = Loan(100, 0.1, 10) assert loan1.principal == 100, "{} != {}".format(loan1.principal, 100) assert loan1.rate == 0.1, "{} != {}".format(loan1.rate, 0.1) assert loan1.time == 10, "{} != {}".format(loan1.time, 10) assert loan1.calculate_monthly_payment() == 16.274539488251154, "{} != {}".format(loan1.calculate_monthly_payment(), 16.274539488251154) assert loan1.calculate_total_interest() == 62.74539488251153, "{} != {}".format(loan1.calculate_total_interest(), 62.74539488251153) assert loan1.calculate_total_owed() == 162.74539488251153,