1.首先分析出顾客类,还有银行类。
2.顾客类具有:用户名,账户,密码,余额,身份证号等属性
3.银行类具有:存钱,取钱,转账,查询,更改密码,注册办理等等功能
4.顾客类:(最好运用属性封装字段)
namespace autoBank
{
class Person
{
public string name;//用户名
public double money;//余额
public string password;//密码
public string idNumber;//身份证号
public string number; //账户
}
}
银行类:
Person[] user = new Person[30];//创建顾客类对象数组
public void CreatAccount()//初始化并添加顾客的方法
{
bool result;
for(int i=0;i<user.Length;i++)
{
if(user[i]==null)
{
user[i]=new Person();
Console.WriteLine("请输入用户名:");
user[i].name = Console.ReadLine();
user[i].number = user[i].name;
do{
Console.WriteLine("请输入密码");
user[i].password = Console.ReadLine();
Console.WriteLine("请再次输入密码:");
string passwords = Console.ReadLine();
result=IsSame(user[i].password,passwords);
if(!result)
{
Console.WriteLine("两次密码不一致,重新输入:");
}
}while(!result);
Console.WriteLine("请输入身份证号:");
user[i].idNumber = Console.ReadLine();
Console.WriteLine("请输入存款金额:");
user[i].money = int.Parse(Console.ReadLine());
Console.WriteLine("账户:{0},用户名:{1},存款金额:{2},创建成功!", user[i].number, user[i].name, user[i].money);
break;
}
}
}
private bool IsSame(string password,string passwords) //判断两次密码是否相同
{
if (password==passwords)
{
return true;
}
return false;
}
public void WithDraw()//取款方法
{
Console.WriteLine("请输入账号:");
string account = Console.ReadLine();
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
Person a = checkOutAccount(account, pwd);
if (a != null)
{
Console.WriteLine("请输入取款金额");
double outmoney = double.Parse(Console.ReadLine());
double result = UserMoney(outmoney, a);
if (result == -1)
{
Console.WriteLine("取款失败");
}
else
{
Console.WriteLine("取款成功,当前金额{0}", a.money);
}
}
else
{
Console.WriteLine("账号或密码不存在");
}
}
private double UserMoney(double outmoney,Person people05)//取款条件的判断
{
if (outmoney > 0)
{
if (outmoney <= people05.money)
{
people05.money -= outmoney;
return people05.money;
}
else
{
return -1;
}
}
else
{
return -1;
}
}
public void Show()//显示余额的方法
{
Console.WriteLine("请输入账号:");
string account = Console.ReadLine();
Console.WriteLine("请输入密码:");
string password =