Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is in python not java thank you Description The goal of this project is to practice some OOP using class, instance variables and methods.

this is in python not java thank you

Description The goal of this project is to practice some OOP using class, instance variables and methods. We will also operate I/O, read/write les and maybe learn a bit about banking activities too... The project must include eight/nine les:

1. Bank.py module containing the class BankAccount and a main function for simple testing.

2. bank-app1.py to bank-app4.py le/modules that contain various applications (to be executed separately).

3. expenses.txt a text le input containing a list of monthly expenses with costs (provided)

4. Amortization.txt a text le output from App3

5. budget.txt a text le output from App4

6. budget-sorted.txt a text le output from App4 (optional-bonus)

The project is designed to be incremental, you can then debug, test and run your code after each new task/option is implemented. After Task 1 done all the other Tasks/options can be completed in any order. Do not forget to comment your code. Make sure you obtain the exact same output for the exact same input for the application examples (this includes syntax, blank spaces, and skipping blank lines). Your program will also be tested with dierent inputs by the graders.

Submission/Grading Proposal

You will regroup all your les into one zip le at the time of submission. This project will be graded out of 100 points:

1. Your program should implement all basic functionality/Tasks and run correctly (90 points).

2. Overall programming style: program should have proper identication, and comments. (10 points).

Task-1- [30pts]

Let us rst work with the module Bank.py. It should contain the following main method:

def main():

#create a bank account named Checking with $1000

acc1=BankAccount("Checking",1000)

#print info about its balance

print(acc1)

#deposit $250

acc1.deposit(250)

#deposit again $250 but record the transaction (i.e print some info)

acc1.deposit(250,True)

1 #withdraw $700 and record the transaction

acc1.withdraw(700,True)

#try to withdraw $850

acc1.withdraw(850,True)

#print new info about its balance

print(acc1)

And it should execute this way:

Checking balance 1000

Checking deposit requested 250

New Checking balance 1500

Checking withdrawal requested 700

New Checking balance 800

Checking withdrawal requested 850

Sorry your withdrawal is limited to 800

Checking balance 0

What you need to implement:

1. The entire Class BankAccount which include the constructor method init and method str as well as the methods deposit and withdraw. You can take inspiration from Lab activity-4 but the methods are slightly dierent here.

2. You will consider here two attributes (instance variables): name and balance.

3. As you can see in the program, the methods deposit and withdraw must accept two arguments. The second argument is a ag that can be set to True or False (it is False by default) which controls if the transaction will be recorded or not. This means that if it is set to False no information will be displayed on the screen. If it is set to True, however, the method should inform the user about the amount requested and report the new balance (in the example this info is indented using the \t symbol). In the withdraw method, if the amount requested is higher than the balance, the balance is now set to zero.

4. For the methods deposit and withdraw, it is required to use the method str . It means that your are not allowed to explicitly write the following string Checking balance ... anywhere within the body of the method or called another method beside str .

5. Tips: implement step by step (commenting/uncommenting the main method as you go along).

App-1- [20pts]

Let us now build our rst application le bank-app1.py that will make use of the class BankAccount that you will need to import (using the instruction: from Bank import BankAccount). Here is the output after execution:

Welcome to App1 ===============

Enter salary and initial balances for Checking and Saving accounts: 1000 535.5 200

Checking balance 535.5

Saving balance 200.0

Month--salary--expense--saving

1--1000--800--150

2--1002--801--150

3--1004--803--150

4--1006--804--150

5--1008--806--151

6--1010--808--151

7--1012--809--151

8--1014--811--152

9--1016--812--152

10--1018--814--152

11--1020--816--153

12--1022--817--153

Checking balance 1142.1441986350806

Saving balance 2019.9325959052426

In this example, we use the multi input: 1000, 535.5, 200 to indicate respectively the salary, the initial balance of the checking account and the initial balance of the saving account.

What you need to implement:

1. You will need to create two object bank accounts (checking and saving) and operate on them.

2. We consider that the salary will increase by 0.2% every month (starting the second month), while 80% of your salary will go in expenses, and 15% will be put (transferred) into your saving account monthly as well.

3. You need to display the budget for the rst 12 months including monthly salary, monthly expenses and monthly savings. These quantities are considered to be of float type but are converted to int when displayed (we also use -- to separate the dierent elds).

4. It is required to use the method deposit and withdraw when operating the checking account.

5. It is required to write a function (not a method) that will accept as arguments: the amount of money you want to transfer, the object bank account that specied the source and the object bank account for the destination. This method can be added inside the le bank-app1.py, however, a good practice is to add it inside the class BankAccount as a static method (that we will see in class).

6. At the end of the program, you will display the new information regarding the two bank accounts.

Remark (just a tip): In order to handle the multi-input as oat numbers, an interesting Python function is the map function that can allow you to operate all the item of an entire list. Indeed, map(,) will apply the function on each member of the list and return a map object that can be turned into a list. Example:

L1=["4","5","6"] #L1 is a list of strings

a,b,c=map(int,L1) #a,b,c are now integer

print(a,b,c) # this will display the integer 4 5 6

## other approach

L2=list(map(int,L1)) #L2 is a list of integer

print(L2) # this will display [4, 5, 6]

App-2- [15pts]

It is time to learn how compound interests are working. Let us see what is happening when bank-app2 is executed:

Welcome to App2 ===============

Enter initial balance and interest rate for saving account: 10000 0.05

Saving balance 10000.0; rate 0.05

How many years will it take to triple my balance?

You will triple your initial balance after 23 years!

Saving balance 31506.563651838176; rate 0.05

Would this be better if I keep contributing 5% of my initial amount every year?

You will triple your initial balance after 15 years!

Saving balance 32021.154051843158; rate 0.05

Would this be even better if in addition my interest rate grows up by 0.5% every year?

You will triple your initial balance after 13 years!

Saving balance 30869.86093452272; rate 0.07377731085069054

At rst, the code is asking the user to enter the initial balance for a saving account as well as the interest rate. We want to study the growth of your saving amount along the years. The program is divided in three distinct task:

1. the program simply returns the number of years it would take for the compound interests to accumulate such that the balance of the saving account would triple.

2. This is similar to task 1, but we consider to add a yearly contribution (5% of the initial amount every year).

3. This is similar to task 2, but now the interest rate will keep increasing by 0.5% every year.

What you need to implement:

1. You will add a new attribute to the Class BankAccount called, for example, rate (could be set to None or 0 by default). You will also modify the st method appropriately (to display the rate). By modifying this Class make sure that all previous applications are still running ne (and executing/displaying as expected)!

2. You will add the method addcompound to the class BankAccount. The formula that modies the balance by adding the accumulated interests in one year.

The formula is: new-balance = current-balance(1 + rate/12)(12)

3. It is also required to make use of the method deposit in Tasks 2 and 3.

App-3- [15pts]

It is time to learn about the painful reality of mortgage... Let us see what is happening when bank-app3 is executed:

Welcome to App3 ===============

Enter amount to borrow, rate, and monthly payment: 350000 0.055 2150

Mortgage balance 350000.0 You will be paying your loan after 300 month! (or 25.0 years!)

You borrowed $350000.0 but paid $645000.0 in total (with interests)

Here the program is asking you to enter the amount you would like to borrow, the interest rate of the loan, and monthly payment you wish to pay, the program should tell you then how long it would take to pay it all back (with interests...).

What you need to implement:

1. You will use the BankAccount class to set the mortgage account where the initial balance (principal) is the amount you wish to borrow.

2. Monthly payments is composed of a part that will go towards paying o your mortgage balance, and a part that is for the interests (they both keep changing every month). Every month, you will then be able to withdraw the following amount from your mortgage account:

monthly-payment(rate/12)current-balance.

If you keep withdrawing every month, you should be able to know how many months it would take to pay o your mortgage and report how much did you pay in total (interests included then).

3. It is here required to use the method withdraw in this program.

4. In addition, you will create a le Amortization.txt that is recording the amortization table along all the months. The le must be created in the same directory than your main code. The le includes, the month number, the amount of principal paid so far, and the amount of interest paid (you wil use to separate the dierent elds). Here what this le should look like for our example (only the rst 10 and last 10 months are reported below for brevity):

Month--Principal paid--Interest paid

1--545.8333333333139--1604.166666666686

2--1094.168402777752--3205.831597222248

3--1645.0166746238247--4804.983325376175

4--2198.3896677158773--6401.610332284123

5--2754.2989536928944--7995.701046307106

6--3312.756157230644--9587.243842769356

7--3873.772956284636--11176.227043715364

8--4437.361082334246--12762.638917665754

9--5003.532320628292--14346.467679371708

10--5572.298510431196--15927.701489568804

:

:

291--331513.55742834066--294136.44257165934

292--333578.8278998872--294221.1721001128

293--335653.5641944284--294296.4358055716 5

294--337737.80969698617--294362.19030301383

295--339831.6079914307--294418.3920085693

296--341935.0028613914--294464.9971386086

297--344048.0382911728--294501.9617088272

298--346170.758466674--294529.241533326

299--348303.20777631295--294546.79222368705

300--350000.0--295000.0 As you may know already you start paying the interests before the principal...

App-4- [10pts]

For this application, the expense.txt le is provided that contains a list of expenses someone may have in one month (this person just records the expenses as they are coming along), here is the le content (Remark: I do not recommend to use notepad to read le on windows):

rent 650.0

utility 112.0

phone 55.0

grocery 34.5

gas 23

restaurant 18.5

gym 12 grocery 14.5

theater 15.5

on-line 13.5

shopping 34

grocery 54.5

grocery 43.2

restaurant 37.5

gym 12

on-line 24.0

grocery 23.0

gas 26

shopping 16

grocery 18.5

shopping 33.0

on-line 15.0

grocery 55.5

theater 17.5

restaurant 17.5

gym 12

grocery 23.5

As you can see many categories are the same, it will be nice to regroup them so we can create a budget. When you execute bank-app4.py you should get:

Welcome to App4 ===============

Ok I load your expenses from expense.txt

I have created the budget file budget.txt

So behind the scenes, the program should read and record all your expenses, regroup the category of expenses, compute their respective total costs, and create a new le budget.txt that reports this budget and nal total cost for the month. This le looks like this:

rent--650.0

utility--112.0

phone--55.0

grocery--267.2

gas--49.0

restaurant--73.5

gym--36.0

theater--33.0

on-line--52.5

shopping--83.0

Total--1411.2

This application is a standalone app (there is no need to import the class BankAccount). You need to read a le and manipulate the data. I give below some tips that you may need or not need (depending on the way you decide to do it).

To check if an item is in a list you could use the in operator, for example:

L1=[4,5,6] #L1 is a list of integer

print(5 in L1) # will return True

print(3 in L1) # will return False

To return the position index of a given item in a list, you could use the method index, for example:

L1=[4,5,6] #L1 is a list of integer

print(L1.index(5)) # will return 1 (item 5 is in position 1)

print(L1.index(4)) # will return 0

print(L1.index(3)) # ==> python error (so make sure the item is in the list)

The sum function returns the sum of all items. For examples:

L1=[4,5,6] #L1 is a list of integer p

rint(sum(L1)) # will return 15

Bonus- [5pts]- No help from Instructor/TA

In application 4, in addition of returning budget.txt, you will return a le budget-sorted.txt that contains the budget sorted by category cost (decreasing order)...so you can see better what were the most expensive expenses. You should be getting:

rent--650.0

grocery--267.2

utility--112.0

shopping--83.0 7

restaurant--73.5

phone--55.0

on-line--52.5

gas--49.0

gym--36.0

theater--33.0

Total--1411.2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions