Question
Portfolio Class Application Using Python finish coding the Portfolio Class which is stored in the portfolio.py file located in Project 12 folder on Blackboard. This
Portfolio Class Application
Using Python finish coding the Portfolio Class which is stored in the portfolio.py file located in Project 12 folder on Blackboard. This class has two objects, checking and savings, of the type BankAccount that is stored in the bankaccount.py file located in Project 12 folder on Blackboard.
Implement five methods:
def deposit(self, amount, account)
def withdraw(self, amount, account)
def transfer(self, amount, account)
def getBalance(self, account)
def __eq__(self, rhsValue)
Here the account string is "S" or "C". 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.
Note: To complete this assignment, you will need to use the portfolio.py, bankaccount.py, and portfolioDemo.py files located in Project 12 folder on Blackboard. You will not be allowed to make any changes to portfolioDemo.py.
----------------------------------------------------
SAMPLE RUN
Savings Balance: 900.00
Checking Balance: 500.00
The two portfolios have the same value.
-------------------------------------------------------------------------
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
----------------------------------------------------------
portfolio.py
## # Define the portfolio class. # from bankaccount import BankAccount
## A class that contains a financial portfolio with checking and savings # accounts. # class Portfolio: ## Constructs a new portfolio with a zero balance. # def __init__(self): self._checking = BankAccount() self._savings = BankAccount()
#Start coding here
----------------------------------------------------------
portfolioDemo.py
## # Demonstrate the portfolio class. # from portfolio import Portfolio
# Create a portfolio. p = Portfolio()
# Perform several transactions. p.deposit(500, "S") p.deposit(1100, "C") p.withdraw(100, "C") p.withdraw(100, "S") p.transfer(500, "C")
# Verify that the balances are as expected. print("Savings Balance: %.2f" % p.getBalance("S")) print("Checking Balance: %.2f" % p.getBalance("C"))
# Compare two portfolios. p2 = Portfolio() p2.deposit(200, "S") p2.deposit(1200, "C") if p == p2: print("The two portfolios have the same value.")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started