using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace MyBank
{
class Bank
{
Card[] twos = new Card[];
public void fx()
{
//第一张卡
Card t1 = new Card();
t1.kahao = "";
t1.mima = "";
t1.names = "小明";
t1.yumoney = ;
//第二张卡
Card t2 = new Card();
t2.kahao = "";
t2.mima = "";
t2.names = "小词";
t2.yumoney = ; twos[] = t1;
twos[] = t2;
}
public void Show() {
for (int i = ; i < twos.Length; i++)
{
if (twos[i] != null)
{
Console.WriteLine("持卡人:{0}\t余额:{1}", twos[i].names, twos[i].yumoney);
}
}
Console.WriteLine("=====================================================");
} //欢迎界面
public void huanying()
{
bool flag = true;
while (flag)
{
Console.WriteLine("\n欢迎进入\t某某某‘s \t的ATM系统\n");
Console.WriteLine("请选择功能模块,按照以下操作↓");
Console.WriteLine("===============================欢迎使用自动银行服务============================= ");
Console.WriteLine("1:开户\t 2:存款\t 3:取款\t 4:查询余额\t 5:转账\t 6:修改密码\t 7:退出");
Console.WriteLine("================================================================================ ");
string choice = Console.ReadLine();
switch (choice)
{
case "":
//开户
kaihu();
break;
case "":
//存款
MoneyIn();
break;
case "":
//取款
MoneyOut();
break;
case "":
//查询余额
chaxunMoney();
break;
case "":
//转账
TransferMoney();
break;
case "":
//修改密码
ModifyPwd();
break;
case"":
//退出
Console.WriteLine("欢迎使用");
break;
default:
Console.WriteLine("您输入的有误,请从新输入!");
Console.WriteLine("");
break;
}
Console.ReadLine();
} }
//开户
public void kaihu()
{
Console.WriteLine("这里是开户功能");
Console.WriteLine("请输入账号:");
string zh = Console.ReadLine();
foreach (Card item in twos)
{
if (item.kahao.Equals(zh))
{
Console.WriteLine("已有账号,请从新输入:");
zh = Console.ReadLine();
}
Console.WriteLine("请输入密码:");
string kaPwd = Console.ReadLine();
Console.WriteLine("请输入预存款金额:");
double money = double.Parse(Console.ReadLine());
Card two = new Card();
two.kahao = zh;
two.mima = kaPwd;
two.yumoney = money;
for (int i = ; i < twos.Length; i++)
{
if (twos[i] == null)
{
twos[i] = two;
Console.WriteLine("恭喜您,开户成功,您的卡号是{0}", zh);
break;
}
}
break;
}
Console.WriteLine("\n是否返回主页面?(y/n)");
char num=char.Parse(Console.ReadLine());
switch (num)
{
case 'y':
huanying();
break;
case 'n':
Console.WriteLine("欢迎下次光临"); break;
}
} //存款
public void MoneyIn()
{
Console.WriteLine("欢迎进入存款区");
Console.WriteLine("请输入账号");
string zh2 = Console.ReadLine();
bool flag = false;
foreach (Card item in twos)
{
if (item != null)
{
if (item.kahao.Equals(zh2))
{
flag = true;
Console.WriteLine("请输入存款金额");
double money = double.Parse(Console.ReadLine());
item.yumoney += money;
Console.WriteLine("存款成功,当前余额为:{0}", item.yumoney); break;
}
}
}
if (flag == false)
{
Console.WriteLine("卡号不存在");
}
Console.WriteLine("\n是否返回主页面?(y/n)");
char num = char.Parse(Console.ReadLine());
switch (num)
{
case 'y':
huanying();
break;
case 'n':
Console.WriteLine("欢迎下次光临!凸^-^凸"); break;
}
}
//取款
public void MoneyOut()
{
Console.WriteLine("请输入账号");
string account = Console.ReadLine();
bool kh = false;
foreach (Card item in twos)
{
if (item != null)
{
if (item.kahao.Equals(account))
{
kh = true;
Console.WriteLine("请输入密码");
string pwd2 = Console.ReadLine();
if (item.mima.Equals(pwd2))
{
Console.WriteLine("请输入取款金额");
double money = double.Parse(Console.ReadLine());
while (money > item.yumoney)
{
Console.WriteLine("余额不足,请重新输入取款金额");
money = double.Parse(Console.ReadLine());
}
item.yumoney -= money;
Console.WriteLine("取款成功");
Console.WriteLine("当前卡内余额{0}", item.yumoney);
break; }
else
{
Console.WriteLine("密码错误");
}
}
}
}
if (kh == false)
{
Console.WriteLine("没有该卡号");
}
Console.WriteLine("\n是否返回主页面?(y/n)");
char num=char.Parse(Console.ReadLine());
switch (num)
{
case 'y':
huanying();
break;
case 'n':
Console.WriteLine("欢迎下次光临!"); break;
}
}
//查询余额
public void chaxunMoney()
{
bool flag = false;
Console.WriteLine("请输入卡号");
string account = Console.ReadLine();
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
foreach (Card item in twos)
{
if (item!=null)
{
if (item.kahao.Equals(account) && item.mima.Equals(pwd))
{
flag=true;
Console.WriteLine("用户名是{0}的账户余额是{1}", item.names, item.yumoney);
break;
}
}
}
if (flag==false)
{
Console.WriteLine("账号有误,请从新输入");
}
Console.WriteLine("\n是否返回主页面?(y/n)");
char num=char.Parse(Console.ReadLine());
switch (num)
{
case 'y':
huanying();
break;
case 'n':
Console.WriteLine("欢迎下次光临!"); break;
}
} //转账
public void TransferMoney()
{
Console.WriteLine("请输入转出卡卡号");
string zc = Console.ReadLine();
bool fromIsOrNot = false;
bool toIsOrNot = false;
foreach (Card item in twos)
{
if (item!=null&&item.kahao.Equals(zc))
{
fromIsOrNot = true; Console.WriteLine("请输入转出卡卡密码");
string pwdFrom = Console.ReadLine();
if (item.mima.Equals(pwdFrom))
{
Console.WriteLine("请输入转入卡卡号");
string zr = Console.ReadLine();
foreach (Card toItem in twos)
{
if (toItem!=null&&toItem.kahao.Equals(zr))
{
toIsOrNot = true;
Console.WriteLine("请输入转账金额");
double money = double.Parse(Console.ReadLine());
while (money > item.yumoney)
{
Console.WriteLine("转账金额不够,请重新输入");
money = double.Parse(Console.ReadLine());
}
item.yumoney -= money;
toItem.yumoney += money;
Console.WriteLine("转账成功,您的余额为{0}",item.yumoney);
break;
} }
if (toIsOrNot==false)
{
Console.WriteLine("转入卡不存在");
}
break;
}
else
{
Console.WriteLine("转出卡密码错误");
}
}
}
if (fromIsOrNot==false)
{
Console.WriteLine("转出卡不存在!");
}
Console.WriteLine("\n是否返回主页面?(y/n)");
char num=char.Parse(Console.ReadLine());
switch (num)
{
case 'y':
huanying();
break;
case 'n':
Console.WriteLine("欢迎下次光临"); break;
}
} //修改密码
public string xinmima;
public void ModifyPwd()
{
Console.WriteLine("请输入账号:");
string no = Console.ReadLine(); for (int i = ; i < twos.Length; i++)
{
if (twos[i] != null)
{
if (twos[i].kahao == no)
{
Console.WriteLine("请输入原密码:");
string mima1 = Console.ReadLine();
for (int j = ; j < ; j++)
{
if (twos[i].mima == mima1)
{
Console.WriteLine("请输入新密码:");
xinmima = Console.ReadLine();
Console.WriteLine("请再次输入新密码:");
if (xinmima == Console.ReadLine())
{
twos[i].mima = xinmima;
Console.WriteLine("账户密码修改成功!!");
break;
} }
} break;
}
}
if (twos[i].kahao != no)
{ Console.WriteLine("您输入的账号不存在!");
break; }
}
Console.WriteLine("\n是否返回主页面?(y/n)");
char num=char.Parse(Console.ReadLine());
switch (num)
{
case 'y':
huanying();
break;
case 'n':
Console.WriteLine("欢迎下次光临");
break;
} } }
}

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()

 namespace MyBank
{
class Program
{
static void Main(string[] args)
{
Bank bank = new Bank(); bank.fx();//卡信息
bank.Show();//展示卡信息
bank.huanying();//欢迎界面
Console.ReadLine();
}
}
}
04-20 12:02