1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace MyBank 8 { 9 class Bank 10 { 11 Card[] twos = new Card[100]; 12 public void fx() 13 { 14 //第一张卡 15 Card t1 = new Card(); 16 t1.kahao = "001"; 17 t1.mima = "001"; 18 t1.names = "小明"; 19 t1.yumoney = 100000; 20 //第二张卡 21 Card t2 = new Card(); 22 t2.kahao = "002"; 23 t2.mima = "002"; 24 t2.names = "小词"; 25 t2.yumoney = 004; 26 27 twos[0] = t1; 28 twos[1] = t2; 29 } 30 public void Show() 31 32 { 33 for (int i = 0; i < twos.Length; i++) 34 { 35 if (twos[i] != null) 36 { 37 Console.WriteLine("持卡人:{0}\t余额:{1}", twos[i].names, twos[i].yumoney); 38 } 39 } 40 Console.WriteLine("====================================================="); 41 } 42 43 //欢迎界面 44 public void huanying() 45 { 46 bool flag = true; 47 while (flag) 48 { 49 Console.WriteLine("\n欢迎进入\t某某某‘s \t的ATM系统\n"); 50 Console.WriteLine("请选择功能模块,按照以下操作↓"); 51 Console.WriteLine("===============================欢迎使用自动银行服务============================= "); 52 Console.WriteLine("1:开户\t 2:存款\t 3:取款\t 4:查询余额\t 5:转账\t 6:修改密码\t 7:退出"); 53 Console.WriteLine("================================================================================ "); 54 string choice = Console.ReadLine(); 55 switch (choice) 56 { 57 case "1": 58 //开户 59 kaihu(); 60 break; 61 case "2": 62 //存款 63 MoneyIn(); 64 break; 65 case "3": 66 //取款 67 MoneyOut(); 68 break; 69 case "4": 70 //查询余额 71 chaxunMoney(); 72 break; 73 case "5": 74 //转账 75 TransferMoney(); 76 break; 77 case "6": 78 //修改密码 79 ModifyPwd(); 80 break; 81 case"7": 82 //退出 83 Console.WriteLine("欢迎使用"); 84 break; 85 default: 86 Console.WriteLine("您输入的有误,请从新输入!"); 87 Console.WriteLine(""); 88 break; 89 } 90 Console.ReadLine(); 91 } 92 93 } 94 //开户 95 public void kaihu() 96 { 97 Console.WriteLine("这里是开户功能"); 98 Console.WriteLine("请输入账号:"); 99 string zh = Console.ReadLine(); 100 foreach (Card item in twos) 101 { 102 if (item.kahao.Equals(zh)) 103 { 104 Console.WriteLine("已有账号,请从新输入:"); 105 zh = Console.ReadLine(); 106 } 107 Console.WriteLine("请输入密码:"); 108 string kaPwd = Console.ReadLine(); 109 Console.WriteLine("请输入预存款金额:"); 110 double money = double.Parse(Console.ReadLine()); 111 Card two = new Card(); 112 two.kahao = zh; 113 two.mima = kaPwd; 114 two.yumoney = money; 115 for (int i = 0; i < twos.Length; i++) 116 { 117 if (twos[i] == null) 118 { 119 twos[i] = two; 120 Console.WriteLine("恭喜您,开户成功,您的卡号是{0}", zh); 121 break; 122 } 123 } 124 break; 125 } 126 Console.WriteLine("\n是否返回主页面?(y/n)"); 127 char num=char.Parse(Console.ReadLine()); 128 switch (num) 129 { 130 case ‘y‘: 131 huanying(); 132 break; 133 case ‘n‘: 134 Console.WriteLine("欢迎下次光临"); 135 136 break; 137 } 138 } 139 140 //存款 141 public void MoneyIn() 142 { 143 Console.WriteLine("欢迎进入存款区"); 144 Console.WriteLine("请输入账号"); 145 string zh2 = Console.ReadLine(); 146 bool flag = false; 147 foreach (Card item in twos) 148 { 149 if (item != null) 150 { 151 if (item.kahao.Equals(zh2)) 152 { 153 flag = true; 154 Console.WriteLine("请输入存款金额"); 155 double money = double.Parse(Console.ReadLine()); 156 item.yumoney += money; 157 Console.WriteLine("存款成功,当前余额为:{0}", item.yumoney); 158 159 break; 160 } 161 } 162 } 163 if (flag == false) 164 { 165 Console.WriteLine("卡号不存在"); 166 } 167 Console.WriteLine("\n是否返回主页面?(y/n)"); 168 char num = char.Parse(Console.ReadLine()); 169 switch (num) 170 { 171 case ‘y‘: 172 huanying(); 173 break; 174 case ‘n‘: 175 Console.WriteLine("欢迎下次光临!凸^-^凸"); 176 177 break; 178 } 179 } 180 //取款 181 public void MoneyOut() 182 { 183 Console.WriteLine("请输入账号"); 184 string account = Console.ReadLine(); 185 bool kh = false; 186 foreach (Card item in twos) 187 { 188 if (item != null) 189 { 190 if (item.kahao.Equals(account)) 191 { 192 kh = true; 193 Console.WriteLine("请输入密码"); 194 string pwd2 = Console.ReadLine(); 195 if (item.mima.Equals(pwd2)) 196 { 197 Console.WriteLine("请输入取款金额"); 198 double money = double.Parse(Console.ReadLine()); 199 while (money > item.yumoney) 200 { 201 Console.WriteLine("余额不足,请重新输入取款金额"); 202 money = double.Parse(Console.ReadLine()); 203 } 204 item.yumoney -= money; 205 Console.WriteLine("取款成功"); 206 Console.WriteLine("当前卡内余额{0}", item.yumoney); 207 break; 208 209 210 } 211 else 212 { 213 Console.WriteLine("密码错误"); 214 } 215 } 216 } 217 } 218 if (kh == false) 219 { 220 Console.WriteLine("没有该卡号"); 221 } 222 Console.WriteLine("\n是否返回主页面?(y/n)"); 223 char num=char.Parse(Console.ReadLine()); 224 switch (num) 225 { 226 case ‘y‘: 227 huanying(); 228 break; 229 case ‘n‘: 230 Console.WriteLine("欢迎下次光临!"); 231 232 break; 233 } 234 } 235 //查询余额 236 public void chaxunMoney() 237 { 238 bool flag = false; 239 Console.WriteLine("请输入卡号"); 240 string account = Console.ReadLine(); 241 Console.WriteLine("请输入密码"); 242 string pwd = Console.ReadLine(); 243 foreach (Card item in twos) 244 { 245 if (item!=null) 246 { 247 if (item.kahao.Equals(account) && item.mima.Equals(pwd)) 248 { 249 flag=true; 250 Console.WriteLine("用户名是{0}的账户余额是{1}", item.names, item.yumoney); 251 break; 252 } 253 } 254 } 255 if (flag==false) 256 { 257 Console.WriteLine("账号有误,请从新输入"); 258 } 259 Console.WriteLine("\n是否返回主页面?(y/n)"); 260 char num=char.Parse(Console.ReadLine()); 261 switch (num) 262 { 263 case ‘y‘: 264 huanying(); 265 break; 266 case ‘n‘: 267 Console.WriteLine("欢迎下次光临!"); 268 269 break; 270 } 271 } 272 273 //转账 274 public void TransferMoney() 275 { 276 Console.WriteLine("请输入转出卡卡号"); 277 string zc = Console.ReadLine(); 278 bool fromIsOrNot = false; 279 bool toIsOrNot = false; 280 foreach (Card item in twos) 281 { 282 if (item!=null&&item.kahao.Equals(zc)) 283 { 284 fromIsOrNot = true; 285 286 Console.WriteLine("请输入转出卡卡密码"); 287 string pwdFrom = Console.ReadLine(); 288 if (item.mima.Equals(pwdFrom)) 289 { 290 Console.WriteLine("请输入转入卡卡号"); 291 string zr = Console.ReadLine(); 292 foreach (Card toItem in twos) 293 { 294 if (toItem!=null&&toItem.kahao.Equals(zr)) 295 { 296 toIsOrNot = true; 297 Console.WriteLine("请输入转账金额"); 298 double money = double.Parse(Console.ReadLine()); 299 while (money > item.yumoney) 300 { 301 Console.WriteLine("转账金额不够,请重新输入"); 302 money = double.Parse(Console.ReadLine()); 303 } 304 item.yumoney -= money; 305 toItem.yumoney += money; 306 Console.WriteLine("转账成功,您的余额为{0}",item.yumoney); 307 break; 308 } 309 310 } 311 if (toIsOrNot==false) 312 { 313 Console.WriteLine("转入卡不存在"); 314 } 315 break; 316 } 317 else 318 { 319 Console.WriteLine("转出卡密码错误"); 320 } 321 } 322 } 323 if (fromIsOrNot==false) 324 { 325 Console.WriteLine("转出卡不存在!"); 326 } 327 Console.WriteLine("\n是否返回主页面?(y/n)"); 328 char num=char.Parse(Console.ReadLine()); 329 switch (num) 330 { 331 case ‘y‘: 332 huanying(); 333 break; 334 case ‘n‘: 335 Console.WriteLine("欢迎下次光临"); 336 337 break; 338 } 339 } 340 341 //修改密码 342 public string xinmima; 343 public void ModifyPwd() 344 { 345 Console.WriteLine("请输入账号:"); 346 string no = Console.ReadLine(); 347 348 for (int i = 0; i < twos.Length; i++) 349 { 350 if (twos[i] != null) 351 { 352 if (twos[i].kahao == no) 353 { 354 Console.WriteLine("请输入原密码:"); 355 string mima1 = Console.ReadLine(); 356 for (int j = 0; j < 3; j++) 357 { 358 if (twos[i].mima == mima1) 359 { 360 Console.WriteLine("请输入新密码:"); 361 xinmima = Console.ReadLine(); 362 Console.WriteLine("请再次输入新密码:"); 363 if (xinmima == Console.ReadLine()) 364 { 365 twos[i].mima = xinmima; 366 Console.WriteLine("账户密码修改成功!!"); 367 break; 368 } 369 370 } 371 } 372 373 break; 374 } 375 } 376 if (twos[i].kahao != no) 377 { 378 379 Console.WriteLine("您输入的账号不存在!"); 380 break; 381 382 } 383 } 384 Console.WriteLine("\n是否返回主页面?(y/n)"); 385 char num=char.Parse(Console.ReadLine()); 386 switch (num) 387 { 388 case ‘y‘: 389 huanying(); 390 break; 391 case ‘n‘: 392 Console.WriteLine("欢迎下次光临"); 393 break; 394 } 395 396 } 397 398 } 399 }
Card
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyBank { class Card { //卡号 public string kahao; //密码 public string mima; //持卡人 public string names; //余额 public double yumoney; } }
Main()
1 namespace MyBank 2 { 3 class Program 4 { 5 static void Main(string[] args) 6 { 7 Bank bank = new Bank(); 8 9 bank.fx();//卡信息 10 bank.Show();//展示卡信息 11 bank.huanying();//欢迎界面 12 Console.ReadLine(); 13 } 14 } 15 }
原文:http://www.cnblogs.com/s1294/p/4910816.html