Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

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

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 an instance variable named self.principal, self.rate, and self.time. You need to implement 3 methods.

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

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.

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 an 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 accountant 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.

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.

skeleton code

#!/usr/bin/env python

import math

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

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):

"""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"

banking_file2 = "banking_statement2.csv"

######################################################################

#######################

# DO NOT CHANGE ANYTHING BELOW HERE

# Testing Loan

loan1 = Loan(100, 0.1, 10)

assert math.isclose(loan1.principal, 100, abs_tol=0.00001), "{} !=

{}".format(loan1.principal, 100)

assert math.isclose(loan1.rate, 0.1, abs_tol=0.00001), "{} !=

{}".format(loan1.rate, 0.1)

assert math.isclose(loan1.time, 10, abs_tol=0.00001), "{} !=

{}".format(loan1.time, 10)

assert math.isclose(loan1.calculate_monthly_payment(),

16.274539488251154, abs_tol=0.00001), "{} !=

{}".format(loan1.calculate_monthly_payment(), 16.274539488251154)

assert math.isclose(loan1.calculate_total_interest(),

62.74539488251153, abs_tol=0.00001), "{} !=

{}".format(loan1.calculate_total_interest(), 62.74539488251153)

assert math.isclose(loan1.calculate_total_owed(), 162.74539488251153,

abs_tol=0.00001), "{} != {}".format(loan1.calculate_total_owed(),

162.74539488251153)

loan1 = Loan(0, 0, 0)

assert math.isclose(loan1.calculate_total_owed(), 0, abs_tol=0.00001),

"{} != {}".format(loan1.calculate_total_owed(), 0)

loan1 = Loan(100, 0.1, 10)

# Testing Client

client1 = Client("client1", 1000, 2000, loan1)

assert client1.name == "client1", "{} != {}".format(client1.name,

"client1")

assert math.isclose(client1.total_savings, 1000, abs_tol=0.00001),

"{} != {}".format(client1.total_savings, 1000)

assert math.isclose(client1.total_in_savings(), 1000,

abs_tol=0.00001), "{} != {}".format(client1.total_in_savings(), 1000)

assert math.isclose(client1.total_checking, 2000, abs_tol=0.00001),

"{} != {}".format(client1.total_checking, 2000)

assert math.isclose(client1.total_in_checking(), 2000,

abs_tol=0.00001), "{} != {}".format(client1.total_in_checking(), 2000)

assert math.isclose(client1.total_borrowed(), 100, abs_tol=0.00001),

"{} != {}".format(client1.total_borrowed(), 100)

assert math.isclose(client1.total_interest(), 62.74539488251153,

abs_tol=0.00001), "{} != {}".format(client1.total_interest(),

62.74539488251153)

assert math.isclose(client1.total_owed(), 162.74539488251153,

abs_tol=0.00001), "{} != {}".format(client1.total_owed(),

162.74539488251153)

# Testing Accountant

accountant1 = Accountant("acct1")

assert accountant1.name == "acct1", "{} !=

{}".format(accountant1.name, "acct1")

assert accountant1.get_client("client1") is None

accountant1.add_client(client1)

assert accountant1.get_client("client1") is client1

assert math.isclose(accountant1.get_number_of_clients(), 1,

abs_tol=0.00001), "{} != {}".format(accountant1.get_number_of_clients(),

1)

assert math.isclose(accountant1.total_in_savings(), 1000,

abs_tol=0.00001), "{} != {}".format(accountant1.total_in_savings(), 1000)

assert math.isclose(accountant1.total_in_checking(), 2000,

abs_tol=0.00001), "{} != {}".format(accountant1.total_in_checking(), 2000)

assert math.isclose(accountant1.total_loaned_out(), 100,

abs_tol=0.00001), "{} != {}".format(accountant1.total_loaned_out(), 100)

assert math.isclose(accountant1.calculate_total_profit(),

62.74539488251153, abs_tol=0.00001),

"{} != {}".format(accountant1.calculate_total_profit(),

62.74539488251153)

client2 = Client("client2", 1000, 2000, Loan(100, 0.1, 20))

accountant1.add_client(client2)

assert math.isclose(accountant1.get_number_of_clients(), 2,

abs_tol=0.00001), "{} != {}".format(accountant1.get_number_of_clients(),

2)

assert math.isclose(accountant1.total_in_savings(), 2000,

abs_tol=0.00001), "{} != {}".format(accountant1.total_in_savings(), 2000)

assert math.isclose(accountant1.total_in_checking(), 4000,

abs_tol=0.00001), "{} != {}".format(accountant1.total_in_checking(), 4000)

assert math.isclose(accountant1.total_loaned_out(), 200,

abs_tol=0.00001), "{} != {}".format(accountant1.total_loaned_out(), 200)

assert math.isclose(accountant1.calculate_total_profit(),

197.66464442760306, abs_tol=0.00001),

"{} != {}".format(accountant1.calculate_total_profit(),

197.66464442760306)

# Testing Bank

bank = Bank("boa")

assert bank.name == "boa", "{} != {}".format(bank.name, "boa")

assert bank.get_accountant("acct1") is None

bank.add_accountant(accountant1)

assert bank.get_accountant("acct1") is accountant1

assert math.isclose(bank.get_number_of_accountants(), 1,

abs_tol=0.00001), "{} != {}".format(bank.get_number_of_accountants(), 1)

assert math.isclose(bank.get_number_of_clients(), 2, abs_tol=0.00001),

"{} != {}".format(bank.get_number_of_clients(), 2)

assert math.isclose(bank.total_in_savings(), 2000, abs_tol=0.00001),

"{} != {}".format(bank.total_in_savings(), 2000)

assert math.isclose(bank.total_in_checking(), 4000, abs_tol=0.00001),

"{} != {}".format(bank.total_in_checking(), 4000)

assert math.isclose(bank.total_loaned_out(), 200, abs_tol=0.00001),

"{} != {}".format(bank.total_loaned_out(), 200)

assert math.isclose(bank.calculate_total_profit(), 197.66464442760306,

abs_tol=0.00001),

"{} != {}".format(bank.calculate_total_profit(),

197.66464442760306)

# Testing create_banks_from_file

# banking_statement.csv

all_banks = create_banks_from_file(banking_file1)

test_bank = all_banks[0]

assert test_bank.name == "boa", "{} != {}".format(test_bank.name,

"boa")

assert math.isclose(test_bank.get_number_of_accountants(), 1,

abs_tol=0.00001), "{} != {}".format(test_bank.get_number_of_accountants(),

1)

assert math.isclose(test_bank.get_number_of_clients(), 2,

abs_tol=0.00001), "{} != {}".format(test_bank.get_number_of_clients(), 2)

assert math.isclose(test_bank.total_in_savings(), 2000,

abs_tol=0.00001), "{} != {}".format(test_bank.total_in_savings(), 2000)

assert math.isclose(test_bank.total_in_checking(), 4000,

abs_tol=0.00001), "{} != {}".format(test_bank.total_in_checking(), 4000)

assert math.isclose(test_bank.total_loaned_out(), 200,

abs_tol=0.00001), "{} != {}".format(test_bank.total_loaned_out(), 200)

assert math.isclose(test_bank.calculate_total_profit(),

197.66464442760306, abs_tol=0.00001),

"{} != {}".format(test_bank.calculate_total_profit(),

197.66464442760306)

# banking_statement2.csv

all_banks = create_banks_from_file(banking_file2)

assert math.isclose(len(all_banks), 2, abs_tol=0.00001), "{} !=

{}".format(len(all_banks), 2)

boa_bank = all_banks[0]

assert boa_bank.name == "boa", "{} != {}".format(boa_bank.name, "boa")

assert math.isclose(boa_bank.get_number_of_accountants(), 2,

abs_tol=0.00001), "{} != {}".format(boa_bank.get_number_of_accountants(),

2)

assert math.isclose(boa_bank.get_number_of_clients(), 3,

abs_tol=0.00001), "{} != {}".format(boa_bank.get_number_of_clients(), 3)

assert math.isclose(boa_bank.total_in_savings(), 3000,

abs_tol=0.00001), "{} != {}".format(boa_bank.total_in_savings(), 3000)

assert math.isclose(boa_bank.total_in_checking(), 6000,

abs_tol=0.00001), "{} != {}".format(boa_bank.total_in_checking(), 6000)

assert math.isclose(boa_bank.total_loaned_out(), 130,

abs_tol=0.00001), "{} != {}".format(boa_bank.total_loaned_out(), 130)

assert math.isclose(boa_bank.calculate_total_profit(),

88.786398813523, abs_tol=0.00001),

"{} != {}".format(boa_bank.calculate_total_profit(),

88.786398813523)

chase_bank = all_banks[1]

assert chase_bank.name == "chase", "{} != {}".format(chase_bank.name,

"chase")

assert math.isclose(chase_bank.get_number_of_accountants(), 1,

abs_tol=0.00001), "{} !=

{}".format(chase_bank.get_number_of_accountants(), 1)

assert math.isclose(chase_bank.get_number_of_clients(), 3,

abs_tol=0.00001), "{} != {}".format(chase_bank.get_number_of_clients(), 3)

assert math.isclose(chase_bank.total_in_savings(), 3000,

abs_tol=0.00001), "{} != {}".format(chase_bank.total_in_savings(), 3000)

assert math.isclose(chase_bank.total_in_checking(), 6000,

abs_tol=0.00001), "{} != {}".format(chase_bank.total_in_checking(), 6000)

assert math.isclose(chase_bank.total_loaned_out(), 0,

abs_tol=0.00001), "{} != {}".format(chase_bank.total_loaned_out(), 0)

assert math.isclose(chase_bank.calculate_total_profit(), 0,

abs_tol=0.00001),

"{} != {}".format(chase_bank.calculate_total_profit(), 0)

if __name__ == '__main__':

main()

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question