使用委托实现信用卡用户定时还款功能

一、功能说明
使用委托实现信用卡定时还款功能
用户的信用卡在具体的日期需要进行还款行为。我们需要使用使用储蓄卡,在扣费时,直接在储蓄卡内扣除费用进行还款。

二、主要解题思路与代码
1、设置信用卡类:用户、扣款金额、扣款时间、现在时间、扣款的储蓄卡;
进行扣款操作。

class CC    //信用卡
    {
        //用户
        public string User;
        //扣款金额
        public int CCMoney;
        //扣款日期
        int DiedLine = 23;
        //当前时间
        public int Day;
        //绑定储蓄卡对象
        public DC DC;
        public CC(string User, int CCMoney, int Day, DC DC)
        {
            this.User = User;
            this.CCMoney = CCMoney;
            this.Day = Day;
            this.DC = DC;
        }
        //获取扣款时间
        public int GetDieLine()
        {
            return this.DiedLine;
        }
        //是否需要还款
        public void RepayMoney()
        {
            Console.WriteLine("尊敬的用户{0}需要还款{1}元,现在您的储蓄卡余额为{2}", this.User, this.CCMoney, this.DC.GetDCMoney());
            DC.SetDCMoney(this.DC.GetDCMoney() - this.CCMoney);
            Console.WriteLine("用户{0}已还款,现在您的储蓄卡余额为{1}", this.User, this.DC.GetDCMoney());
        }
        public void NoRepayMoney()
        {
            Console.WriteLine("尊敬的用户{0},您的还款日期为{1},时间未到,无需还款。", this.User, this.DiedLine);
            Console.WriteLine("您的储蓄卡当前余额为{0}。", this.DC.GetDCMoney());
        }
    }

2、设置储蓄卡类:储蓄金额、每次还款后更新当前金额。

class DC    //储蓄卡
    {
        //储蓄金额
        private int DCMoney;
        public DC(int Money)
        {
            this.DCMoney = Money;
        }
        //设置储蓄当前金额
        public void SetDCMoney(int NowMoney)
        {
            this.DCMoney = NowMoney;
        }
        //获取储蓄金额
        public int GetDCMoney()
        {
            return this.DCMoney;
        }
    }

3、委托类

class Delegate  //委托
    {
        public delegate void RepayMoney();
        public event RepayMoney Repay;
        public void RequestRepay()
        {
            if (Repay != null)
            {
                Repay();
            }
        }
    }

4、主程序

class Program   //主程序
    {
        static void Main(string[] args)
        {
            Delegate RD = new Delegate();
            DC D1 = new DC(88888);
            CC People = new CC("muxin", 2200, 23, D1);
            if (People.GetDieLine() == People.Day)
                RD.Repay += new Delegate.RepayMoney(People.RepayMoney);
            else RD.Repay += new Delegate.RepayMoney(People.NoRepayMoney);
            People.Day = 27;
            if (People.GetDieLine() == People.Day)
                RD.Repay += new Delegate.RepayMoney(People.RepayMoney);
            else RD.Repay += new Delegate.RepayMoney(People.NoRepayMoney);
            RD.RequestRepay();
        }
    }

三、结果截图

四、Gitee
https://gitee.com/muxinji/windows/commit/d54cb89116fbdd6ba408cae789b8d7441341c0f1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值