C#基础-040 设计User类,该类有用户名,密码,存款金额。该类用户有存款,取款的方法;设计 CreditUser,该类新增信用额度。用户每次提升信用额度后,每刷卡刷爆三次,信用额度提升1000

 class User
    {
        private string UserName;
        private string PassWord;
        private int DepositMoney;
        private int count = 0;

        public string UserName1
        {
            get
            {
                return UserName;
            }

            set
            {
                UserName = value;
            }
        }

        public string PassWord1
        {
            get
            {
                return PassWord;
            }

            set
            {
                PassWord = value;
            }
        }

        public int DepositMoney1
        {
            get
            {
                return DepositMoney;
            }

            set
            {
                DepositMoney = value;
            }
        }

        public int Count
        {
            get
            {
                return count;
            }

            set
            {
                count = value;
            }
        }

        public User()
        {

        }

        public User(string userName, string passWord, int depositMoney)
        {
            UserName1 = userName;
            PassWord1 = passWord;
            DepositMoney1 = depositMoney;
        }

        public User(int count)
        {
            this.Count = count;
        }

        public void SaveMoney(int money)
        {
            DepositMoney1 += money;
        }
        public void DrawMoney(int money)
        {
            if (DepositMoney1 >= money)
            {
                DepositMoney1 -= money;
            }
            else if(10000+DepositMoney1<money)
            {
                Count++;
                Console.WriteLine("卡被你刷爆了");
                DepositMoney = 10000+1000 * Count;
            }
            else
            {
                Console.WriteLine("您透支了{0}元",money-DepositMoney1);
            }
        }
    }
 class CreditUser : User
    {
        private int LineOfCredit = 10000;

        public CreditUser(int lineOfCredit)
        {
            LineOfCredit = lineOfCredit;
        }

        public CreditUser(string userName, string passWord, int depositMoney)
        {
            UserName1 = userName;
            PassWord1 = passWord;
            DepositMoney1 = depositMoney;
        }

        public int LineOfCredit1
        {
            get
            {
                return LineOfCredit;
            }

            set
            {
                LineOfCredit = value;
            }
        }

        public void AddLOC()
        {
            if (Count >=3)
            {
                LineOfCredit1 += 1000;
                Count = 0;
            }
        }
    }

main方法参考代码:

 CreditUser user = new CreditUser("张三", "123456", 50000);
 user.SaveMoney(20000);
 Console.WriteLine(user.DepositMoney1);
 user.DrawMoney(75000);//透支了,但没有刷爆
 user.DrawMoney(90000);//第一次刷爆     
 Console.WriteLine("您的当前信用额度为{0}", user.LineOfCredit1);
 user.AddLOC();
 user.DrawMoney(90000);//第二次刷爆
 Console.WriteLine("您的当前信用额度为{0}", user.LineOfCredit1);
 user.AddLOC();
 user.DrawMoney(90000);//第三次刷爆
 Console.WriteLine("您的当前信用额度为{0}", user.LineOfCredit1);
 user.AddLOC();
 Console.WriteLine("您当前的信用额度为{0}", user.LineOfCredit1);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值