天天看點

【無标題】委托實作信用卡使用者定時還款功能

using System;

namespace text

{

    //儲蓄卡

    class GetPayout

    {

        private int Payout;

        public GetPayout(int Payout)

            {

            this.Payout=Payout;

            }

        //擷取金額

        public int NeedMoney()

        {

            return this.Payout;

        }

        //剩餘的金額

        public void LeftMoney(int NowMoney)

        {

            this.Payout = NowMoney;

        }

    }

    //信用卡

    class CreditPayin

    {

        public int Payin;

        public int Diedline;

        public GetPayout PA;//綁定儲蓄卡

        public CreditPayin(int Payin,int Diedline,GetPayout PA)

        {

            this.Payin = Payin;

            this.Diedline = Diedline;

            this.PA = PA;

        }

        //時間到了

        public void nowpay()

        {

            Console.WriteLine("您的總資産還有{0}元", this.PA.NeedMoney());

            Console.WriteLine("該月需要還款{0}元。",this.Payin);

            if(this.PA.NeedMoney() > this.Payin)

            {

                Console.WriteLine("您已經還款成功:");

                PA.LeftMoney(this.PA.NeedMoney()+this.Payin);

                Console.WriteLine("您的總資産還剩{0}元。",PA.NeedMoney()); 

            }

            else

            {

                Console.WriteLine("您新儲蓄卡内的錢不夠,請及時充值.");

            }

        }

    }

    class JudgeA

    {

        public void print()

        {

            Console.WriteLine("出現錯誤!");

        }

    }

    class Delegate

    {

        public delegate void Paydelegate();

        public event Paydelegate Paydelegate_event;

        public void Occor()

        {   

            Console.WriteLine("還款期到了");

            if(Paydelegate_event!=null)

                Paydelegate_event();

        }

    }

    class program

    {

        static void Main(string[] args)

        {

            GetPayout getPayout1=new GetPayout(50000);

            CreditPayin creditPayin1= new CreditPayin(-2000, 15, getPayout1);

            GetPayout getPayout2 = new GetPayout(10000);

            CreditPayin creditPayin2= new CreditPayin(-1500, 28, getPayout2);

            GetPayout getPayout3 = new GetPayout(100000);

            CreditPayin creditPayin3 = new CreditPayin(-3000, 15, getPayout3);

            GetPayout getPayout4= new GetPayout(1000);

            CreditPayin creditPayin4 = new CreditPayin(-3000, 23, getPayout4);

            List<CreditPayin> CreditPayins = new List<CreditPayin>();

            CreditPayins.Add(creditPayin1);

            CreditPayins.Add(creditPayin2);

            CreditPayins.Add(creditPayin3);

            CreditPayins.Add(creditPayin4);

            Delegate paydelegate=new Delegate();

            foreach (CreditPayin C in CreditPayins)

                paydelegate.Paydelegate_event += new Delegate.Paydelegate(C.nowpay);

            paydelegate.Occor();

        }

    }

}

【無标題】委托實作信用卡使用者定時還款功能