Question

In: Computer Science

I need to add this checkpoint to an existing code that i have in python Checkpoint...

I need to add this checkpoint to an existing code that i have in python

Checkpoint 1:

Once you have created and tested the Bank Account Class create subclasses to the BankAccount class. There should be two subclasses, CheckingAccount and SavingsAccount. You should add interest_rate to the parent BankAccount class. To the CheckingAccount add variables called per_check_fee default to false and allow_overdraft default to True. To SavingsAccount add the variable transactions_per_month, default it to 5. Create instances of CheckingAccount and SavingsAccount and test them to ensure all the methods work. You should also verify that BankAccount still behaves correctly. You will need to extend the __init__ and __str__ routines from your BankAccount class.

The BankAccount, CheckingAccount, SavingsAccount, and BankAccountTester should all be separate files. You will need to import the BankAccount into the SavingsAccount, CheckingAccount, and BankAccountTester. You will need to import the BankAccount into the SavingsAccount and CheckingAccount classes.

To set default values for a parameter, you say paramater_name = default_value.

In testing you will need to create an instance of the BankingAccount, and test all the methods, deposit and withdraw, and try to withdraw more money than is in the account. You must also create instances of the checking account testing the same methods.

Existing code:

class BankAccount():

    def __init__(self, name, id, ssn, balance=0.0):
        self.__name = name
        self.__account_id = id
        self.__ssn = ssn
        self.__balance = balance

    def deposit(self, amount):
        if amount <= 0:
            print('Error: Deposit amount ${} is in negative'.format(amount))
            return
        else:
            self.__balance += amount
            print('Success: Amount ${} deposited succesfully')

    def withdraw(self, amount):
        if amount <= 0:
            print('Error: Withdraw amount ${} is in negative'.format(amount))
            return
        else:
            if amount <= self.__balance:
                self.__balance -= amount
                print('Success: Amount ${} withdrawn succesfully')
            else:
                print('Error: Insufficient funds.')

    def __str__(self):
        return 'Name: {}, Account ID: {}, SSN: {}, Current Balance: ${:.2f}'.format(
            self.__name, self.__account_id, self.__ssn, self.__balance
        )

=========================================================================

from BankAccount import BankAccount


def main():
    account = BankAccount('John Doe', 1234, '234-789-1221', 1000)
    print(account)

    print('Depositing $100 into account')
    account.deposit(100)
    print(account)

    print('Withdrawing $950 from account')
    account.withdraw(950)
    print(account)


    print('Withdrawing $400 from account')
    account.withdraw(400)
    print(account)


main()

====================================================================

Solutions

Expert Solution

Since no use of the newly added variables are mentioned, I just implemented new 2 classes and added new variable interest rate to bankaccount class. let me know If you need any features to be implemented.

 
class BankAccount:

    def __init__(self, name, id, ssn, balance=0.0,interest_rate=0.0):
        self.__name = name
        self.__account_id = id
        self.__ssn = ssn
        self.__balance = balance
        self.__interest_rate = interest_rate

    def deposit(self, amount):
        if amount <= 0:
            print('Error: Deposit amount ${} is in negative'.format(amount))
            return
        else:
            self.__balance += amount
            print('Success: Amount ${} deposited succesfully'.format(amount))

    def withdraw(self, amount):
        if amount <= 0:
            print('Error: Withdraw amount ${} is in negative'.format(amount))
            return
        else:
            if amount <= self.__balance:
                self.__balance -= amount
                print('Success: Amount ${} withdrawn succesfully'.format(amount))
            else:
                print('Error: Insufficient funds.')

    def __str__(self):
        return 'Name: {}, Account ID: {}, SSN: {}, Current Balance: ${:.2f}'.format(
            self.__name, self.__account_id, self.__ssn, self.__balance
        )
# Subclass Checking Account
class CheckingAccount(BankAccount):

    def __init__(self, name, id, ssn, balance=0.0,interest_rate=0.0,per_check_fee = False, allow_overdraft = True):
        super().__init__(name, id, ssn, balance,interest_rate)
        self.__per_check_fee = per_check_fee
        self.__allow_overdraft = allow_overdraft

    def __str__(self):
        return '{}, Per Check Fee: {}, Overdraft Allowed: {}'.format(
            super().__str__(), self.__per_check_fee, self.__allow_overdraft)


# Subclass Savings Account
class SavingsAccount(BankAccount):

    def __init__(self, name, id, ssn, balance=0.0, interest_rate=0.0, transactions_per_month=5):
        super().__init__(name, id, ssn, balance, interest_rate)
        self.__transactions_per_month = transactions_per_month

    def __str__(self):
        return '{}, Transactions Per Month: {}'.format(
            super().__str__(), self.__transactions_per_month)

Test Code

# This is my package structure. change it according to yours

from Bank.BankAccount import CheckingAccount,SavingsAccount
def main():
    account = CheckingAccount('John Doe', 1234, '234-789-1221', 1000,6.5,True,False)
    print(account)

    print('Depositing $100 into account')
    account.deposit(100)
    print(account)

    print('Withdrawing $950 from account')
    account.withdraw(950)
    print(account)

    print('Withdrawing $400 from account')
    account.withdraw(400)
    print(account)
    account = SavingsAccount('Jane Doe', 1234, '234-789-1120', 1050, 7.5,10)
    print('Depositing $100 into account')
    account.deposit(850)
    print(account)

    print('Withdrawing $950 from account')
    account.withdraw(950)
    print(account)

    print('Withdrawing $400 from account')
    account.withdraw(400)
    print(account)

main()


Related Solutions

this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j...
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j a. How many bits does it take to encode ? b. How many bits needed in register file to store the data?
(Python) How would I add this input into my code? "Enter Y for Yes or N...
(Python) How would I add this input into my code? "Enter Y for Yes or N for No:" as a loop. def getMat(): mat = np.zeros((3, 3)) print("Enter your first 3 by 3 matrix:") for row in range(3): li = [int(x) for x in input().split()] mat[row,0] = li[0] mat[row,1] = li[1] mat[row,2] = li[2] print("Your first 3 by 3 matrix is :") for i in range(3): for k in range(3): print(str(int(mat[i][k]))+" ",end="") print() return mat def checkEntry(inputValue): try: float(inputValue) except...
I need the code in python where I can encrypt and decrypt any plaintext. For example,...
I need the code in python where I can encrypt and decrypt any plaintext. For example, the plaintext "hello" from each of these Block Cipher modes of Operation. Electronic Code Block Mode (ECB) Cipher block Mode (CBC) Cipher Feedback Mode (CFB) Output feedback Mode (OFB) Counter Mode (CTR) Here is an example, Affine cipher expressed in C. Encryption: char cipher(unsigned char block, char key) { return (key+11*block) } Decryption: char invcipher(unsigned char block, char key) { return (163*(block-key+256)) }
I need this code to be written in Python: Given a dataset, D, which consists of...
I need this code to be written in Python: Given a dataset, D, which consists of (x,y) pairs, and a list of cluster assignments, C, write a function centroids(D, C) that computes the new (x,y) centroid for each cluster. Your function should return a list of the new cluster centroids, with each centroid represented as a list of x, y: def centroid(D, C):
I need to implement a code in python to guess a random number. The number must...
I need to implement a code in python to guess a random number. The number must be an integer between 1 and 50 inclusive, using the module random function randint. The user will have four options to guess the number. For each one of the failed attempts, the program it should let the user know whether is with a lower or higher number and how many tries they have left. If the user guess the number, the program must congratulate...
I need to take the code i already have and change it to have at least...
I need to take the code i already have and change it to have at least one function in it. it has to include one function and one loop. I already have the loop but cant figure out how to add a function. I thought i could create a funciton to call to the totalCost but not sure how to do it. Help please. #include #include //main function int main(void) {    char userName [20];    char yesOrNo [10];   ...
Hi, I need the HTML5 code for the below. About Me **Would like to add a...
Hi, I need the HTML5 code for the below. About Me **Would like to add a image of a plane or something related to travel here. Mia Jo I am taking this class to earn my Computer programmer CL1. Things I Like to Do: Spend time with family Traveling People Watch Places I Want to Go or Have Visited: Dubai- December'18 Enjoyed shopping and the desert safari the most. Cuba- August '18 Enjoyed learning about the culture and history. China-...
I need this Java code transform to Python Code PROGRAM: import java.util.Scanner; public class Main {...
I need this Java code transform to Python Code PROGRAM: import java.util.Scanner; public class Main { static int count=0; int calculate(int row, int column) { count++; if(row==1&&column==1) { return 0; } else if(column==1) { return ((200+calculate(row-1,column))/2); } else if(column==row) { return (200+calculate(row-1,column-1))/2; } else { return ((200+calculate(row-1,column-1))/2)+((200+calculate(row-1,column))/2); }    } public static void main(String[] args) { int row,column,weight; Main m=new Main(); System.out.println("Welcome to the Human pyramid. Select a row column combination and i will tell you how much weight the...
In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT