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)) }
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...
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...
**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
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...
How do I add the information below to my current code that I have also posted...
How do I add the information below to my current code that I have also posted below. <!DOCTYPE html> <html> <!-- The author of this code is: Ikeem Mays --> <body> <header> <h1> My Grocery Site </h1> </header> <article> This is web content about a grocery store that might be in any town. The store stocks fresh produce, as well as essential grocery items. Below are category lists of products you can find in the grocery store. </article> <div class...
Hello, I Have create this code and Tried to add do while loop but it gives...
Hello, I Have create this code and Tried to add do while loop but it gives me the error in string answar; and the areas where I blod So cloud you please help me to do ( do while ) in this code. // Program objective: requires user to input the data, program runs through the data,calcualtes the quantity, chacks prices for each iteam intered,calautes the prices seperatly for each item, and calculates the amount due without tax, and then...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT