class CreditCard:
def __init__(self,customer,bank,acnt,limit):
self._customer=customer
self._bank=bank
self._account=acnt
self._limit=limit
self._balance=0
#客户
def get_customer(self):
return self._customer
#银行
def get_bank(self):
return self._bank
#账户
def get_account(self):
return self._account
#信用额度
def get_limint(self):
return self._limit
#已用信用额度
def get_balance(self):
return self._balance
def charge(self,price):
if price+self._balance>self._limit:
return False
else:
self._balance+=price
return True
def make_payment(self,amount):
self._balance-=amount
class PredatoryCreditCard(CreditCard):
def __init__(self,customer,bank,acnt,limit,apr):
super().__init__(customer,bank,acnt,limit)
self._apr=apr
#当尝试收费超过信用卡额度,收取5美元费用
def charge(self,price):
success=super().charge(price)
if not success:
self._balance+=5
return success
#未清按月计算利息
def process_month(self):
if self._balance>0:
monthly_factor=pow(1+self._apr,1/12)
self._balance*=monthly_factor
数据结构 信用卡类及继承的简单实现
最新推荐文章于 2021-09-04 10:16:56 发布