class Account { public decimal account_balance=1000000m; public decimal querey_balance(decimal account_banlance) { return account_balance; } public decimal save_money(decimal save_money) { account_balance += save_money; return account_balance; } public decimal draw_money(decimal draw_money) { if (draw_money > account_balance) { Console.WriteLine("余额不足"); return account_balance; } else { account_balance -= draw_money; return account_balance; } } }
Account account=new Account();
Console.WriteLine("请输入您的需要的服务的数字代号:1.查询余额 2.存款 3.取款 4.取卡");
int products = Convert.ToInt32(Console.ReadLine()); try { do { Console.Clear(); if (products > 0 || products < 5) { switch (products) { case 1: Console.WriteLine("您的存款金额为{0}", account.account_balance); break; case 2: Console.WriteLine("请输入您的存款金额"); decimal save_money = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("您存入的金额为{0},您现在的账号余额为{1}", save_money, account.save_money(save_money)); break; case 3: Console.WriteLine("请输入您的取款金额"); decimal draw_money = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("您现在的账号余额为{1}", account.draw_money(draw_money)); break; } } else Console.WriteLine("请输入正确的操作指令"); Console.WriteLine("请输入您的需要的服务的数字代号:1.查询余额 2.存款 3.取款 4.取卡"); products = Convert.ToInt32(Console.ReadLine()); } while (products != 4); } catch { Console.WriteLine("请您输入正确的操作指令"); }
{ account_balance -= draw_money; return account_balance; } } }
C#超基础:ATM机小实例
最新推荐文章于 2024-07-05 19:08:04 发布