类4

来源:互联网 发布:淘宝新店免费推广软件 编辑:程序博客网 时间:2024/05/29 14:47

银行存款是一项经典的循环判断及类知识的总结,可以说一道题包罗万象

从整道题来看,分六个小问:开户,登录,存钱,取钱,查询,销户。

所用到的知识有:

1数据类型

2创建方法

3循环

4判断                                                           

5嵌套6参数7死循环for(;;){ } 8数据转换9锁屏。

整道题的步奏如下:

class Bank
    {
        string a ,b ;
        double c;
        //开户
        public void Open() {
            a = "fsq";
            b = "123";
            c = 2000;
            Console.WriteLine("开户成功");
        }
        //登录
        public void Load() {
            Console.WriteLine("请输入密码"点击打开链接);
            for(int i=2;i>=0;i--)
            {
                string d=Console.ReadLine();
                if(d==b)
                { 
                 Console.WriteLine("登录成功");
                 break;
                }
                else
                {
                    if (i == 0)
                    {
                        Console.WriteLine("你已没有机会");
                    }
                    else
                    {
                        Console.WriteLine("你还有" + i + "次机会");
                    }
                }
            }


        }
        //存钱
        public void Save(int money) {
            c = c + money;        
        }
        //取钱
        public void Get(int money) 
        {
            if (c - money <= 0)
            {
                Console.WriteLine("账户余额不足");
            }
            else 
            {
                c = c - money;
                Console.WriteLine("取款成功");
            }  
        }
        //查询
        public void Demand() {
            Console.WriteLine(a+"你的余额为"+c);
        }
        //销户
        public void Colse() {
            a = "";
            b = "";
            c = 0.0;
            Console.WriteLine("您的账户已消除");
        }
        static void Main(string[] args) {
            Console.WriteLine("欢迎来到权氏银行");
            Console.WriteLine("1 开户 ");
            Console.WriteLine("2 登录 ");
            Console.WriteLine("3 存钱");
            Console.WriteLine("4 取钱 ");
            Console.WriteLine("5 查询 ");
            Console.WriteLine("6 销户 ");
            Bank com = new Bank();
            for (; ; )
            {
                string s = Console.ReadLine();
                switch (s)
                {
                    case "1":
                        com.Open();
                        break;
                    case "2":
                        com.Load();
                        break;
                    case "3":
                        Console.WriteLine("请输入存款金额");
                        string m = Console.ReadLine();
                        int mm = int.Parse(m);
                        com.Save(mm);
                        break;
                    case "4":
                        Console.WriteLine("请输入取款金额");
                        string  n= Console.ReadLine();
                        int nn = int.Parse(n);
                        com.Get(nn);
                        break;
                    case "5":
                        com.Demand();
                        break;
                    case "6":
                        com.Colse();
                        break;
                }
            }
            Console.ReadKey();
        }
    }

如果你有什么好的想法的话,请来狗刨学习网交流,对此题还有什么不懂得的话也可以来这里看看,如果你想在C#语言上大展手脚的话,请来狗刨学习网培训一下。

0 0
原创粉丝点击