开发工具:
文件大小: 34kb
下载次数: 0
上传时间: 2008-12-17
详细说明: 老师认为较成功的程序 // ATM.cs // ATM项目中的ATM类源文件 using System; using System.Collections.Generic; using System.Text; namespace ATM { class ATM { private const string quitCode = "20060824"; private Bank bank; public ATM(Bank bank) { this.bank = bank; } public void Start() { while (true) { // 主界面 PrintLogo(); Console.WriteLine(" 1. 开户 "); Console.WriteLine(" 2. 登录 "); Console.WriteLine("----------------------------------------------"); Console.WriteLine(""); Console.Write("你的选择(回车结束):"); string code = Console.ReadLine(); // quit system if (code == quitCode) return; if (code == "1") // 开户 OpenAccount(); else if (code == "2") // 登陆 LoginAccount(); } } private void LoginAccount() { PrintLogo(); Console.WriteLine(" 请输入你的帐号的用户名和密码 "); Console.WriteLine("----------------------------------------------"); Console.WriteLine(""); string name = Input("用户名(回车结束):"); string password = Input("密码(回车结束):"); // 登录帐号 Account account; if (!bank.LoginAccount(name, password, out account)) { Console.Write("登录错误,请检查用户名和密码是否正确。按Enter键继续..."); Console.Read(); } else { ManageAccount(ref account); } } private void OpenAccount() { PrintLogo(); Console.WriteLine(" 请输入你的帐号的用户名和密码 "); Console.WriteLine("----------------------------------------------"); Console.WriteLine(""); string name = Input("用户名(回车结束):"); string password = Input("密码(回车结束):"); // 开户 Account account; if (!bank.OpenAccount(name, password, out account)) { Console.Write("开户错误,用户名可能已经存在。按Enter键继续..."); Console.Read(); } else { Print("开户", 0, account); Pause(); ManageAccount(ref account); } } private void ManageAccount(ref Account account) { while (true) { // 管理帐号界面 PrintLogo(); Console.WriteLine(" 1. 存款 "); Console.WriteLine(" 2. 取款 "); Console.WriteLine(" 3. 查询余额 "); Console.WriteLine(" 4. 修改密码 "); Console.WriteLine(" 5. 退出 "); Console.WriteLine("----------------------------------------------"); Console.WriteLine(""); Console.Write("你的选择(回车结束):"); string code = Console.ReadLine(); decimal amount; bool succeed; switch (code) { case "1": amount = InputNumber("\n输入存款数目:"); succeed = account.Deposit(amount); if (succeed) { Print("存入", amount, account); } else { Console.WriteLine("存款失败!"); } Pause(); break; case "2": amount = InputNumber("\n输入取款数目:"); succeed = account.Withdraw(amount); if (succeed) { Print("取出", amount, account); } else { Console.WriteLine("取款失败!"); } Pause(); break; case "3": Print(account); Pause(); break; case "4": string oldPassword = Input("当前密码(回车结束):"); string newPassword = Input("新密码(回车结束):"); succeed = account.ChangePassword(oldPassword, newPassword); if (succeed) Console.WriteLine("密码修改成功!"); else Console.WriteLine("密码修改失败!"); Pause(); break; case "5": return; default: break; } } } private void PrintLogo() { Console.WriteLine("\n----------------------------------------------"); Console.WriteLine(" {0}自动取款机 用户第一 服务之上 ", bank.Name); Console.WriteLine("----------------------------------------------"); } private string Input(string prompt) { Console.Write(prompt); string str = Console.ReadLine(); while (str == "") { Console.Write("不能为空,{0}", prompt); str = Console.ReadLine(); } return str; } private decimal InputNumber(string prompt) { Console.Write(prompt); string s = Console.ReadLine(); decimal amount = 0; try { amount = Decimal.Parse(s); } catch (Exception) // 捕获任何异常 { Console.Write("输入的数值格式不正确,请重新输入!"); // 提示错误 amount = InputNumber(prompt); // 递归调用InputNumber } return amount; } private void Pause() { Console.Write("按Enter键继续..."); Console.Read(); } private void Print(string operation, decimal amount, Account account) { Console.WriteLine("---------------------------"); Console.WriteLine("姓名: {0}", account.Name); Console.WriteLine("{0}: {1}", operation, amount); Console.WriteLine("余额: {0}", account.Balance); Console.WriteLine("---------------------------"); Console.WriteLine("{0}成功!", operation); } public void Print(Account account) { Console.WriteLine("---------------------------"); Console.WriteLine("姓名: {0}", account.Name); Console.WriteLine("余额: {0}", account.Balance); Console.WriteLine("---------------------------"); } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.