using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ICBC{ class Program { static void Main(string[] args) { Bank b = new Bank(); b.c(); Console.ReadLine(); } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ICBC{ class User { private String name; //姓名 private int id; //账号 private int pwd; //密码 private double money; //余额 public double Money { get { return money; } set { money = value; } } public String Name { get { return name; } set { name = value; } } public int Pwd { get { return pwd; } set { pwd = value; } } public int Id { get { return id; } set { id = value; } } public void ShowInfo() { Console.WriteLine("账户{0},用户名{1},存款余额{2},", Id, name, money); } public void ShowAll(User[] user) { foreach (User item in user) { if (item != null) { item.ShowInfo(); } else { break; } } } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ICBC{ class Bank { User[] user = new User[10]; User users = new User(); #region 菜单 public void test() { Console.WriteLine("-----------欢迎使用自动银行服务----------"); Console.WriteLine("0:开户 1:存款 2:取款 3:转账 4:查询余额 5:修改密码 6:退出"); int i = int.Parse(Console.ReadLine()); xz(i); } public void xz(int i) { switch (i) { case 0: kz(); test(); break; case 1: cz(); test(); break; case 2: qz(); test(); break; case 3: zz(); test(); break; case 4: cx(); test(); break; case 5: xg(); test(); break; case 6: Console.WriteLine("退出成功"); break; } } #endregion #region 初始化 public void c() { user[0] = new User(); user[0].Name = "张三"; user[0].Id = 1001; user[0].Money = 10000; user[0].Pwd = 123; user[1] = new User(); user[1].Name = "李四"; user[1].Id = 1002; user[1].Money = 10000; user[1].Pwd = 123; user[2] = new User(); user[2].Name = "王五"; user[2].Id = 1003; user[2].Money = 10000; user[2].Pwd = 123; users.ShowAll(user); test(); } #endregion #region 开户 public void kz() { for (int i = 0; i < user.Length; i++) { if (user[i] == null) { user[i] = new User(); Console.WriteLine("请输入用户名"); user[i].Name = Console.ReadLine(); if (user[i] == null) { user[i] = null; Console.WriteLine("用户名不可以为空"); break; } Console.WriteLine("请输入密码"); user[i].Pwd = int.Parse(Console.ReadLine()); if (user[i].Pwd == 0) { user[i] = null; Console.WriteLine("密码不可以为空"); break; } Console.WriteLine("请输入存款金额 至少10元"); user[i].Money = int.Parse(Console.ReadLine()); if (user[i].Money < 10) { Console.WriteLine("请至少存入10元"); user[i] = null; break; } user[i].Id = 1001 + i; Console.WriteLine("创建成功"); user[i].ShowInfo(); break; } } } #endregion #region 存款 public void cz() { for (int u = 0; u < user.Length; u++) { Console.WriteLine("请输入存款账户"); int iid = int.Parse(Console.ReadLine()); int a = Pdzh(iid); if (a != -1) { Console.WriteLine("请输入密码"); int pwd = int.Parse(Console.ReadLine()); bool o = true; Xh(ref pwd, ref o,user[a]); int y = Pdmm(pwd, user[a]); if (o==false) { break; } if (y != 0) { Console.WriteLine("请输入存款金额"); int c = int.Parse(Console.ReadLine()); if (c > 0) { user[a].Money += c; user[a].ShowInfo(); break; } else { Console.WriteLine("请存大于0的金额"); } } else { } } else { Console.WriteLine("不存在此账户请重新输入"); } } } #endregion #region 取款 public void qz() { for (int i = 0; i < user.Length; i++) { Console.WriteLine("请输入账号"); int iid = int.Parse(Console.ReadLine()); int a = Pdzh(iid); if (a != -1) { Console.WriteLine("请输入密码"); int pwds = int.Parse(Console.ReadLine()); bool o=true; Xh(ref pwds, ref o, user[a]); int b = Pdmm(pwds, user[a]); if (o == false) { break; } if (b != 0) { Console.WriteLine("请输入取款金额"); int q = int.Parse(Console.ReadLine()); int p = Pdye(q, user[a]); if (p != 0) { user[a].Money -= q; Console.WriteLine("取款成功"); user[a].ShowInfo(); break; } else { Console.WriteLine("余额不足"); } } else { Console.WriteLine("密码错误"); } } else { Console.WriteLine("不存在此账户"); } } } #endregion #region 转账 public void zz() { for (int i = 0; i < user.Length; i++) { Console.WriteLine("请输入转出的账号"); int iid = int.Parse(Console.ReadLine()); int a = Pdzh(iid); if (a != -1) { Console.WriteLine("请输入密码"); int pwd = int.Parse(Console.ReadLine()); bool o = true; Xh(ref pwd, ref o, user[a]); int p = Pdmm(pwd, user[a]); if (o == false) { break; } if (p != 0) { Console.WriteLine("请输入转入的账号"); int iids = int.Parse(Console.ReadLine()); int aa = Pdzh(iids); if (aa != -1) { Console.WriteLine("请输入金额"); int m = int.Parse(Console.ReadLine()); int w = Pdye(m, user[a]); if (w != 0) { user[a].Money -= m; user[aa].Money += m; Console.WriteLine("转账成功"); user[a].ShowInfo(); user[aa].ShowInfo(); break; } else { Console.WriteLine("余额不足"); } } else { Console.WriteLine("此账户不存在请重新输入"); } } else { Console.WriteLine("密码错误请重新输入"); } } else { Console.WriteLine("此账户不存在请重新输入"); } } } #endregion #region 查询 public void cx() { for (int i = 0; i < user.Length; i++) { Console.WriteLine("请输入账号"); int iid = int.Parse(Console.ReadLine()); int a = Pdzh(iid); if (a != -1) { Console.WriteLine("请输入密码"); int pwds = int.Parse(Console.ReadLine()); bool o = true; Xh(ref pwds, ref o, user[a]); int b = Pdmm(pwds, user[a]); if (o == false) { break; } if (b != 0) { user[a].ShowInfo(); break; } else { Console.WriteLine("密码错误"); } } else { Console.WriteLine("账户不存在请重新输入"); } } } #endregion #region 修改 public void xg() { for (int i = 0; i < user.Length; i++) { Console.WriteLine("请输入要修改的账户"); int iid = int.Parse(Console.ReadLine()); int a = Pdzh(iid); if (a != -1) { Console.WriteLine("请输入密码"); int pwds = int.Parse(Console.ReadLine()); bool o = true; Xh(ref pwds, ref o, user[a]); int b = Pdmm(pwds, user[a]); if (o == false) { break; } if (b != 0) { Console.WriteLine("请输入要修改的密码"); int pwdd = int.Parse(Console.ReadLine()); Console.WriteLine("请再次输入要修改的密码"); int pwddd = int.Parse(Console.ReadLine()); if (pwdd == pwddd) { user[a].Pwd = pwdd; } Console.WriteLine("修改成功"); break; } else { Console.WriteLine("密码错误"); } } else { Console.WriteLine("此账户不存在请重新输入"); } } } #endregion #region 判断账号 public int Pdzh(int iid) { int a = -1; for (int i = 0; i < user.Length; i++) { if (user[i] == null) { break; } if (user[i] != null && iid == user[i].Id) { a = i; break; } } return a; } #endregion #region 判断密码 public int Pdmm(int pwd, User u) { int i = 0; if (pwd == u.Pwd) { i = 1; } return i; } #endregion #region 判断余额 public int Pdye(int q, User u) { int i = 0; if (q <= u.Money) { i = 1; } return i; } #endregion #region 循环 public void Xh(ref int pwd,ref bool o, User u) { while (pwd != u.Pwd) { Console.WriteLine("密码错误 输入1重新输入 输入2返回主页面"); int i = int.Parse(Console.ReadLine()); if (i == 1) { Console.WriteLine("请重新输入"); pwd = int.Parse(Console.ReadLine()); } else if(i==2) { o = false; break; } } #endregion } }}