Question

For all problems you must: Write a Python (.py) program Test, debug, and execute the Python...

For all problems you must:

  1. Write a Python (.py) program
  2. Test, debug, and execute the Python program
  3. Submit a copy of your commented source code on-line
  1. (11 pts.) Create a Person class that contains the following members: name, email, and phone_number Provide a constuctor that initializes all three members with data passed to the constructor. Add a __str__ method that returns a string printing the data members. Provide methods that allows you to get and set all three data members. Demonstrate the correctness of your program with a couple sample test cases.
  2. (11 pts.) Create an Account class that contains the following members: Person, account_number and balance where composition is used for the Person data member. Provide a constuctor that initializes all three members with the data passed to the constructor. Provide a method that allows you to get the account_number and methods that allow you to get and set the Person and balance data members. Additionally, for this class any attempt in a method or constructor to set a negative balance should result in the balance being set to 0. (Note: You must use composition for the Person data member). Demonstrate the correctness of your program with a couple sample test cases.
  3. (11 pts.) Create a Savings_Account class that is a derived class of the Account class. Add a minimum_balance data member and deposit and withdrawl methods. The class should contain a constructor method that utilize the Account constructor but also ensures that no object is created if the provided balance is less than the provided minimum_balance. A __str__ method that displays all data members should also be provided. Additionally, any call to the withdrawl method should fail if the balance would drop below the minimum_balance. Demonstrate the correctness of your program with a couple sample test cases.
  4. (11 pts.) Create a Loan_Account class that is a derived class of the Account class. Add a maximum_balance data member and deposit and withdrawl methods. The class should contain a constructor method that utilize the Account constructor but also ensures that no object is created if the provided balance is greater than the provided maximum_balance. A __str__ method that displays all data members should also be provided. Additionally, any call to the withdrawl method should fail if the balance would exceed the maximum_balance and any call to deposit should fail if he balance would drop below 0. Demonstrate the correctness of your program with acouple sample test cases.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have implemented the classes but i ran out of time to write the test cases for them.

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

class Person():
    def __init__(self, n, e, p):
        self.name = n
        self.email = e
        self.phone = p

    def __str__(self):
        return self.name + ' ' + self.email + ' ' + str(self.phone)

    def get_name(self):
        return self.name
    def set_name(self,n):
        self.name=n

    def get_phone(self):
        return self.phone
    def set_phone(self,p):
        self.phone=p

    def get_email(self):
        return self.email
    def set_name(self,e):
        self.email=e

jon = Person('John','John@coursera.com','456-789-1233')
print(jon)
jon.set_phone('457-888-9999')
print(jon)

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

class Account():

    def __init__(self,person,num,bal):
        self.person=person
        self.account_number=num
        self.balance=bal
        if self.balance<0:
            self.balance=0

    def get_Person(self):
        return self.person
    def set_Person(self,p):
        self.person=p
    def get_AccountNumber(self):
        return self.account_number
    def set_AccountNumber(self,num):
        self.account_number=num
    def get_balance(self):
        return self.balance
    def set_balance(self,bal):
        if bal>0:
            self.balance=bal

class Savings_Account(Account):
    def __init__(self,person,num,bal,min_bal):
        super().__init__(person,num,bal)
        self.minimum_balance=min_bal

    def deposit(self,amount):
        if amount>0:
            self.balance+=amount

    def withdrawl(self,amount):
        if 0<amount and amount<=self.balance:
            self.balance-=amount

    def __str__(self):
        return self.person+" Account number: "+str(self.account_number)+\
            ", Balance: $"+str(self.balance)

class Loan_Account(Account):
    def __init__(self,person,num,bal,max_balance):
        super().__init__(person, num, bal)
        self.max_balance = max_balance

    def withdrawl(self, amount):
        if 0 < amount and amount <= self.balance:
            self.balance -= amount

    def __str__(self):
        return self.person + " Account number: " + str(self.account_number) + \
               ", Balance: $" + str(self.balance)

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

Add a comment
Know the answer?
Add Answer to:
For all problems you must: Write a Python (.py) program Test, debug, and execute the Python...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • code must be in java. Assignment 5 Purpose In this assignment, you will implement a class...

    code must be in java. Assignment 5 Purpose In this assignment, you will implement a class hierarchy in Java. Instructions The class hierarchy you will implement is shown below account Package Account manager Package SavingAccount CheckingAccount AccountManager The descriptions of each class and the corresponding members are provided below. Please note that the Visibility Modifiers (public, private and protected) are not specified and you must use the most appropriate modifiers Class AccountManager is a test main program. Create it so...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • The class declaration (interface) and the function definitions (implementation) must be in separate files - the...

    The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. Write a class called BankAccount that has: a string data member called customerName, a string data member called customerID, and a double data member called customerBalance a constructor that takes two strings and a double (name, ID, balance) and uses them...

  • When answering this question, can you please specify what you name your files? Thank you! Write a...

    When answering this question, can you please specify what you name your files? Thank you! Write a Java application, and an additional class to represent some real-world entity. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods). The class will: a. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT