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?
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)) }
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...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an ARM assembly program to calculate the value of the following function: f(y) = 3y^2 – 2y + 10 when y = 3. My Code below, that needs comments added: FunSolve.s LDR R6,=y LDR R1,[R6] MOV R2,#5 MOV R3,#6 MUL R4,R1,R1 MUL R4,R4,R2 MUL R5,R1,R3 SUB R4,R4,R5 ADD R4,R4,#8 st B st y DCD 3
This is the code what I have for doubly linked list for STACK. This is Python...
This is the code what I have for doubly linked list for STACK. This is Python language and I want anyone to help me with the following questions. Can you check for me if it is good Doubly Linked List? ####THIS IS THE ENTIRE ASSIGNMENT#### ADD the Following feature: Include a class attribute in the container class called name. In the implementation - Pod: You should ask the user to enter the name of the container and the program should...
Make a java program of Mickey I have the starter program but I need to add...
Make a java program of Mickey I have the starter program but I need to add eyes and a smile to it. import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JFrame; public class Mickey extends Canvas { public static void main(String[] args) { JFrame frame = new JFrame("Mickey Mouse"); Canvas canvas = new Mickey(); canvas.setSize(400, 400); canvas.setBackground(Color.white); frame.add(canvas); frame.pack(); frame.setVisible(true); } public void paint(Graphics g) { Rectangle bb = new Rectangle(100, 100, 200, 200); mickey(g, bb); } public void...
I have the following python code. I get the following message when running it using a...
I have the following python code. I get the following message when running it using a test script which I cannot send here: while textstring[iterator].isspace(): # loop until we get other than space character IndexError: string index out of range. Please find out why and correct the code. def createWords(textstrings): createdWords = [] # empty list for textstring in textstrings: # iterate through each string in trxtstrings iterator = 0 begin = iterator # new begin variable while (iterator <...
Java homework problem: I need the code to be able to have a message if I...
Java homework problem: I need the code to be able to have a message if I type in a letter instead of a number. For example, " Please input only numbers". Then, I should be able to go back and type a number. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class LoginGui {    static JFrame frame = new JFrame("JFrame Example");    public static void main(String s[]) {        JPanel panel...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT