数据结构 信用卡类及继承的简单实现

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值