C# 银行取款

    xiaoxiao2021-12-12  2

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class User { public string name; public string id; public string mima; public double cunkuan; public string zhanghao; //取款 public double qukuanf(double qukuan) { if (qukuan > 0) { if (qukuan <= cunkuan) { cunkuan = cunkuan - qukuan; return cunkuan; } else { return -1; } } else { return -1; } } //存款 public double cunkuanf(double cunkuan1) { if (cunkuan1 > 0) { cunkuan = cunkuan + cunkuan1; return cunkuan; } else { return -1; } } } } 账户类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Bank { User a = new User(); User[] p = new User[3]; //初始化 public void zhanghu() { p[0] = new User(); p[0].zhanghao = "13"; p[0].name = "李四"; p[0].mima = "1236"; p[0].id = "11111111"; p[0].cunkuan = 70000; p[1] = new User(); p[1].zhanghao = "12"; p[1].name = "张三"; p[1].mima = "1234"; p[1].id = "123456789"; p[1].cunkuan = 80000; p[2] = new User(); p[2].zhanghao = "14"; p[2].name = "王五"; p[2].mima = "1235"; p[2].id = "2222222"; p[2].cunkuan = 90000; } //取款 public void qukuanf2() { Console.WriteLine("请输入账号"); string qwe = Console.ReadLine(); Console.WriteLine("请输入密码"); string zxc = Console.ReadLine(); User o = qaz(qwe, zxc); if (o != null) { Console.WriteLine("请输入取款金额"); double qukuan = double.Parse(Console.ReadLine()); double e = o.qukuanf(qukuan); if (e == -1) { Console.WriteLine("取款失败!"); fuwu(); } else { Console.WriteLine("取款成功!当前余额为:" + e); fuwu(); } } else { Console.WriteLine("输入有误!"); fuwu(); Console.ReadLine(); } } //存款 public void cunkuanf2() { Console.WriteLine("请输入账号"); string qwe = Console.ReadLine(); User o = yanzheng1(qwe); if (o != null) { Console.WriteLine("请输入存款金额"); double t = double.Parse(Console.ReadLine()); double w = o.cunkuanf(t); Console.WriteLine("存款成功!当前余额为" + w); fuwu(); } else { Console.WriteLine("输入有误!"); fuwu(); Console.ReadLine(); } } //菜单 public void fuwu() { foreach (var item in p) { Console.WriteLine("用户名:{0},账号;{1},省份证:{2},余额:{3}", item.name, item.zhanghao, item.id, item.cunkuan); } Console.WriteLine("===========欢迎使用自动银行服务==========="); Console.WriteLine("1.存款 2.取款 3.转账 4.查询余额 5.修改密码 6.退出"); Console.WriteLine("=========================================="); int i = int.Parse(Console.ReadLine()); switch (i) { case 1: cunkuanf2(); break; case 2: qukuanf2(); break; case 3: zhuanzhang(); break; case 4: cha(); break; case 5: mima(); break; case 6: //退出 break; } Console.ReadLine(); } //验证 public User qaz(string qwe, string zxc) { foreach (User item in p) { if (qwe.Equals(item.zhanghao) && zxc.Equals(item.mima)) { return item; //fuwu(); } } return null; } //转账 public void zhuanzhang() { double yu1 = 0; double yu2 = 0; Console.WriteLine("请输入账号"); string qwe = Console.ReadLine(); Console.WriteLine("请输入密码"); string zxc = Console.ReadLine(); User o = qaz(qwe, zxc); if (o != null) { Console.WriteLine("请输转帐款金额"); double qukuan9 = double.Parse(Console.ReadLine()); yu1 = o.qukuanf(qukuan9); Console.WriteLine("请输入转入账号"); string k = Console.ReadLine(); User y = yanzheng1(k); if (y != null) { double t = qukuan9; yu2 = y.cunkuanf(t); } } else { Console.WriteLine("输入有误!"); Console.ReadLine(); } Console.WriteLine("转出账户余额为:" + yu1 + "转入账户余额为:" + yu2); } //账号验证 public User yanzheng1(string qwe) { foreach (User item in p) { if (qwe.Equals(item.zhanghao)) { return item; } } return null; } //查询余额 public void cha() { Console.WriteLine("请输入账号"); string qwe = Console.ReadLine(); Console.WriteLine("请输入密码"); string zxc = Console.ReadLine(); User o = qaz(qwe, zxc); if (o != null) { Console.WriteLine("账户的余额是{0:N}", o.cunkuan); fuwu(); } else { Console.WriteLine("当前用户不存在!"); fuwu(); } } //修改密码 public void mima() { Console.WriteLine("请输入账号"); string qwe = Console.ReadLine(); Console.WriteLine("请输入密码"); string zxc = Console.ReadLine(); User o = qaz(qwe, zxc); if (o != null) { Console.WriteLine("请输入密码"); string zxc1 = Console.ReadLine(); Console.WriteLine("请输入密码"); string zxc2 = Console.ReadLine(); if (zxc.Equals(zxc1)&&zxc1.Equals(zxc2)) { Console.WriteLine("请输入新密码!"); zxc = Console.ReadLine(); o.mima =zxc; Console.WriteLine("修改密码成功!"); fuwu(); } else { Console.WriteLine("两次用户不一致“"); } } else { Console.WriteLine("当前用户不存在!"); } } } } 银行类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { Bank s = new Bank(); s.zhanghu(); s.fuwu(); } } } 主方法::
    转载请注明原文地址: https://ju.6miu.com/read-900277.html

    最新回复(0)