In: Computer Science
Give an example of a class containing attributes and operations. Instantiate (create) an object of your class
//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)