C sharp 实现银行ATM机程序.doc_第1页
C sharp 实现银行ATM机程序.doc_第2页
C sharp 实现银行ATM机程序.doc_第3页
C sharp 实现银行ATM机程序.doc_第4页
C sharp 实现银行ATM机程序.doc_第5页
免费预览已结束,剩余3页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

用c# 实现银行ATM机项目对于做开发的人来说,没有什么比做出项目、实现功能更开心的事了。以下是使用microsoft visual studio 2008作为开发工具,制作出的银行ATM机的程序程序实现截图程序结构1、新建一个C#项目2、创建如下几个文件1、 Customer.cs文件内容using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 银行提款机模拟_面向对象_文件访问_ class Customer public Customer(string name,string account, string password,double money) this.Name = name; this.Account = account; this.Password = password; this.money = money; public string Name get;set; public string Accountget;set; public string Password get; set; private double money; public double Money get return money; public bool Save(double money) this.money += money; /this的用法 return true; public bool Draw(double money) if(this.Moneymoney) return false; else this.money -= money; return true; public bool ChangePsw(string newPsw) if(newPsw=this.Password|newPsw=|newPsw=null) return false; else this.Password = newPsw; return true; 2、文件using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 银行提款机模拟_面向对象_文件访问_ class Machine private List list = new List(); /保存客户的集合 private Customer currentCustomer = null; /表示当前在柜员机上操作的客户 public Machine() /得到所有字符串 string temp = OperFile.ReadFile();/调用之前写好的静态方法 /对字符串按行进行拆分,换行的字符为rn string arr = temp.Split(n, r); /根据每一行的字符串还原出客户对象 foreach (string s in arr) string strs = s.Split(,); if(strs.Length!=4) /采用rn拆分后可能出现无效字符串 continue; Customer c = new Customer(strs0, strs1, strs2, double.Parse(strs3); list.Add(c); /将创建完的客户对象加入到集合中 private void ChangePsw() Console.WriteLine(请输入旧密码); string temp = Console.ReadLine(); Console.WriteLine(请输入新密码); string newPsw = Console.ReadLine(); if (currentCustomer.Password = temp & currentCustomer.Password != newPsw) currentCustomer.Password = newPsw; Console.WriteLine(密码修改成功); else Console.WriteLine(修改不成功); private bool CustomerLogin() Console.WriteLine(请输入卡号); string account = Console.ReadLine(); Console.WriteLine(请输入密码); string psw = Console.ReadLine(); foreach (Customer c in list) if (c.Account = account & c.Password = psw) Console.WriteLine(登录成功); this.currentCustomer = c; return true; else Console.WriteLine(输入有误); return false; return false; private bool Save() Console.WriteLine(请输入要存款的金额); string temp = Console.ReadLine(); double d = double.Parse(temp); currentCustomer.Save(d); Console.WriteLine(存款成功); return true; private bool Draw() Console.WriteLine(请输入要取的金额); string temp = Console.ReadLine(); double d = double.Parse(temp); bool b = currentCustomer.Draw(d); if (b = true) Console.WriteLine(取款成功); return true; else Console.WriteLine(取款不成功); return false; private void QueryMoney() if (currentCustomer != null) /实际上前面几个例子都要写这一句 double d = currentCustomer.Money; Console.WriteLine(您的余额为:0, d); else Console.WriteLine(数据异常); public void MainOperation() /在函数中进行业务流程的定义 bool b = CustomerLogin(); bool isContinue = true; if (b = true) do Console.WriteLine(请选择所需操作:1 取款 , 2 存款 3 查询余额 ,4 修改密码 ,0 退出); string temp = Console.ReadLine(); switch (temp) case 1: Draw(); break; case 2: Save(); break; case 3: QueryMoney(); break; case 4: ChangePsw(); break; case 5: break; Console.WriteLine(是否继续 Y/N); temp = Console.ReadLine(); if (temp = n) isContinue = false; while (isContinue = true); 3、文件using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;namespace 银行提款机模拟_面向对象_文件访问_ class OperFile / / 将文本写到文件上 / / 要写到文件上的内容 public static void WriteFile(string contents) FileStream fs = new FileStream(Account.txt, FileMode.OpenOrCreate); byte byt = Encoding.Default.GetBytes(contents); fs.Write(byt, 0, byt.Length); fs.Close(); / / 从文件上读取内容 / / 文件上的所有内容 public static string ReadFile() /用于存放最后的结果 string temp = ; FileStream fs = new FileStream(Account.txt, FileMode.Open); /文件不存在,则会出错,出错不管,以后再说 byte byt = new byte1024; int realRead = 0; do realRead=fs.Read(byt,0,byt.Length); temp = temp +Encoding.Default.GetString(byt,0,realRead); /该句性能较差,以后需要优化 while(realRead=byt.Length); fs.Close(); return temp;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论