Question

In: Computer Science

Give an example of a class containing attributes and operations. Instantiate (create) an object of your...

Give an example of a class containing attributes and operations. Instantiate (create) an object of your class

Solutions

Expert Solution

//example of a Customer class containing attributes and operations


class Customer(object):
    """A customer of XYZ Bank with a checking account. Customers have the
    following properties:

    Attributes:
        name: A string representing the customer's name.
        current_balance: A float tracking the current current_balance of the customer's account.

    Operations: A customer can perform following operation like withdraw_money() ,check_balance(),deposite_money()


    """

    def __init__(self, name, current_balance=0.0):
        """Return a Customer object whose name is *name* and starting
        current_balance is *current_balance*."""
        self.name = name
        self.current_balance = current_balance

    def check_balance(self):
        return self.current_balance

    def withdraw_money(self, amount):
        """Return the current_balance remaining after withdrawing *amount* """
        if amount > self.current_balance:
            raise RuntimeError('Insufficient Balance!! .')
        self.current_balance -= amount
        return self.current_balance

    def deposit_money(self, amount):
        """Return the current_balance  after depositing *amount* """
        self.current_balance = self.current_balance + amount
        return self.current_balance




# creating obect  

customer = Customer("Ravi",1000)

""" Performing operations """
#checking current balance
print(customer.current_balance)

# adding money to account
customer.deposit_money(5000)

# withdraw_money

customer.withdraw_money(1000)

#checking current balance
print(customer.current_balance)




Related Solutions

Instructions 1. Create a class named after your favorite object in the whole world. For example,...
Instructions 1. Create a class named after your favorite object in the whole world. For example, if you love pizza, then create a class called Pizza.java. This class should not have a main method (1 point) 2. Create Instance Variables (attributes) (2 point) Create at least 3 private instance fields (attributes) for your class You must use at least 3 different data types for your fields 3. Create getter (accessor) and setter (mutator) methods   Create a getter (accessor) method for...
C++ Instantiate a binary search tree object and create such tree using elements of the sequence...
C++ Instantiate a binary search tree object and create such tree using elements of the sequence 8,3,10, 1,6,9, 14, 4,7, 13 with 8 as root of the tree. Find maximum and minimum elements of the tree, successor(10) and predecessor(13), print the inorder, postorder and preorder traversal of the tree.
Create a Class to contain a customer order Create attributes of that class to store Company...
Create a Class to contain a customer order Create attributes of that class to store Company Name, Address and Sales Tax. Create a public property for each of these attributes. Create a class constructor without parameters that initializes the attributes to default values. Create a class constructor with parameters that initializes the attributes to the passed in parameter values. Create a behavior of that class to generate a welcome message that includes the company name. Create a Class to contain...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS COVERING THE FOLLOWING POINTS: 1) COUNTING NUMBER OF OBJECTS CREATED ( NO OBJECT ARRAY TO BE USED) USING ROLE OF STATIC MEMBER 2) SHOWING THE VALID INVALID STATEMENTS IN CASE OF STATIC MEMBER WITH NON STATIC MEMBER FUNCTION, NON STATIC MEMBERS OF CLASS WITH STATIC MEMBER FUNCTION, BOTH STATIC. SHOW THE ERRORS WHERE STATEMENTS ARE INVALID. 3) CALL OF STATIC MEMBER FUNCTION, DECLARATION OF...
Using Java Summary Create a Loan class, instantiate and write several Loan objects to a file,...
Using Java Summary Create a Loan class, instantiate and write several Loan objects to a file, read them back in, and format a report. Project Description You’ll read and write files containing objects of the Loan class. Here are the details of that class: Instance Variables: customer name (String) annual interest percentage (double) number of years (int) loan amount (double) loan date (String) monthly payment (double) total payments (double) Methods: getters for all instance variables setters for all instance variables...
Question: Class Diagram – Make a class diagram for 'Patient Appointment' showing attributes and operations /...
Question: Class Diagram – Make a class diagram for 'Patient Appointment' showing attributes and operations / methods. Associations are optional. References from earlier questions/instructions from the project: 1) Use Case Tables – Consider the Mentcare system for which we considered requirements in the previous module. Make 2 use case tables for this system (table examples may be found in the textbook, section 5.2, and in the content guides). Be sure to consider who the actors would be in each case...
In python- Create a class defined for Regression. Class attributes are data points for x, y,...
In python- Create a class defined for Regression. Class attributes are data points for x, y, the slope and the intercept for the regression line. Define an instance method to find the regression line parameters (slope and intercept). Plot all data points on the graph. Plot the regression line on the same plot.
Create a car class with three attributes: year, mpg, speed and list of owners. The class...
Create a car class with three attributes: year, mpg, speed and list of owners. The class also should have 2 methods called accelerate and brake. Whenever the car accelerates, its speed is increased by 30 and whenever the car brakes, its speed is reduced by 60. add a constructor to the class, which takes year, mpg, and speed as input implement a magic method that prints the car information including year, speed and mpg. That is, for a car object,...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. this is c sharp program please type the whole program.
Create a class named GameCharacter to define an object as follows: The class should contain class...
Create a class named GameCharacter to define an object as follows: The class should contain class variables for charName (a string to store the character's name), charType (a string to store the character's type), charHealth (an int to store the character's health rating), and charScore (an int to store the character's current score). Provide a constructor with parameters for the name, type, health and score and include code to assign the received values to the four class variables. Provide a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT