Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python Implement a class Portfolio . This class has two objects, checking and savings, of the type BankAccount that was developed in bankaccount.py .

In Python

Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount that was developed in bankaccount.py.

Implement four methods:

def deposit(self, amount, account) def withdraw(self, amount, account) def transfer(self, amount, account) def getBalance(self, account)

Here the account string is "C" or "S". For the deposit or withdrawal, it indicates which account is affected. For a transfer, it indicates the account from which the money is taken; the money is automatically transferred to the other account.

Please include: Comment, docstring and output of the code

bankaccount.py:

##

# This module defines a class that models a bank account.

#

## A bank account has a balance that can be changed by deposits and withdrawals.

#

class BankAccount :

## Constructs a bank account with a given balance.

# @param initialBalance the initial account balance (default = 0.0)

#

def __init__(self, initialBalance = 0.0) :

self._balance = initialBalance

## Deposits money into this account.

# @param amount the amount to deposit

#

def deposit(self, amount) :

self._balance = self._balance + amount

## Makes a withdrawal from this account, or charges a penalty if

# sufficient funds are not available.

# @param amount the amount of the withdrawal

#

def withdraw(self, amount) :

PENALTY = 10.0

if amount > self._balance :

self._balance = self._balance - PENALTY

else :

self._balance = self._balance - amount

## Adds interest to this account.

# @param rate the interest rate in percent

#

def addInterest(self, rate) :

amount = self._balance * rate / 100.0

self._balance = self._balance + amount

## Gets the current balance of this account.

# @return the current balance

#

def getBalance(self) :

return self._balance

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

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions

Question

LO4 Provide an overview of four challenges facing HR today.

Answered: 1 week ago