用户类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankBank
{
class Users
{
public string _name; //账户姓名
public string _password; //账户密码
public string _idcard; //身份证号
public double _money; //存款余额
public string _account; //帐号
//存款方法
public double AddMoney(double money)
{
_money += money;
return _money;
}
//取款方法
public double JianMoney(double money)
{
if (_money >= money)
{
_money =_money - money;
return _money;
}
else
{
return -3;
}
}
}
}
银行类
writeline使用方法pythonusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankBank
{
class Bank
{
/
/创建Users类对象数组
Users [] user = new Users[3];
//系统菜单
public void Menu()
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("制作者:徐也轩");
Console.WriteLine("==============================欢迎使用自动银行服务==============================");
Console.WriteLine("1:开户 2:存款 3:取款 4:转账 5:查询余额 6:修改密码 7:退出");
Console.WriteLine("================================================================================");
Console.WriteLine("请选择:");
int num = int.Parse(Console.ReadLine());
switch (num)
{
case 1:
Console.WriteLine("没有此服务");
Console.WriteLine("有关业务请咨询北大青鸟中关村校区S1T137班刘怀武老师");
Menu();
break;
case 2:
AddMoneyInput();
Menu();
break;
case 3:
JianMoneyGet();
Menu();
break;
case 4:
ZInput();
Menu();
break;
case 5:
show();
Menu();
break;
case 6:
Xpassword();
Menu();
break;
case 7:
Console.WriteLine("系统退出谢谢使用!SB");
Console.WriteLine("你怎么能退出呢 这么好的系统?");
Console.WriteLine("魔兽世界二区 拉文凯斯服务器 罗刃罗琳");
break;
default:
Console.WriteLine("您的输入有误,请重新输入")
;
Menu();
break;
}
Console.WriteLine();
}
//初始化3个账户信息
public void initial()
{
user[0] = new Users();
user[0]._account = "179708064356";
user[0]._name = "王丽丽";
user[0]._password = "1234";
user[0]._idcard = "210050619890808185";
user[0]._money = 1000;
user[1] = new Users();
user[1]._account = "179708064359";
user[1]._name = "张颖颖";
user[1]._password = "4321";
user[1]._idcard = "510010679891231127";
user[1]._money = 2000;
user[2] = new Users();
user[2]._account = "179708064369";
user[2]._name = "刘华";
user[2]._password = "4567";
user[2]._idcard = "410207************";
user[2]._money = 8000;
}
//转出操作的输入方法
public void ZInput()
{
Console.WriteLine("版权所有:徐也轩");
Console.WriteLine("请输入转出帐号:");
string account = Console.ReadLine();
Console.WriteLine("请输入转出账户密码:");
string password = Console.ReadLine();
Console.WriteLine("请输入转入帐号:");
string inputAccount = Console.ReadLine();
Console.WriteLine("请输入转账金额:");
double Money = double.Parse(Console.ReadLine());
double FromMoney =0;
double ToMoney =0;
int iRet =Transfer( account, password, inputAccount, Money,ref FromMoney,ref ToMoney);
if (iRet == -1)
{
Console.WriteLine("转出账户帐号或密码不正确");
}
else if(iRet==-2)
{
Console.WriteLine("转入账户帐号不正确");
}
else if (iRet == -3)
{
Console.WriteLine("转出账户余额不足,转账失败");
}
else
{
Console.WriteLine("转账成功,转出帐号{0}余额为:{1},转入帐号{2}余额为{3}",account,FromMoney,inputAccount,ToMoney);
}
}
//存款操作的输入方法
public void AddMoneyInput()
{
Console.WriteLine("请输入要存款的帐号");
string InputAccount = Console.ReadLine();
Users AImoney = ChenkUserByAccount(InputAccount);
if (AImoney == null)
{
Console.WriteLine("存款帐号不存在");
AddMoneyInput();
}
else
{
Console.WriteLine("请输入要存入的金额:");
double money = double.Parse(Console.ReadLine());
double moneys =AImoney.AddMoney(mon
ey);
Console.WriteLine("存款成功,帐号{0}的余额为{1}",AImoney._account,moneys);
}
}
//取款操作的输入方法
public void JianMoneyGet()
{
Console.WriteLine("请输入要取款的帐号:");
string GetAccount = Console.ReadLine();
Console.WriteLine("请输入密码");
string GetPassword = Console.ReadLine();
Console.WriteLine("请输入要取款的金额:");
double GetMoney = double.Parse(Console.ReadLine());
Users Getuser = CheckUser(GetAccount, GetPassword);
if (Getuser == null)
{
Console.WriteLine("帐号或密码输入错误!请重新输入");
JianMoneyGet();
}
else
{
double Money = Getuser.JianMoney(GetMoney);
if (Money == -3.0)
{
Console.WriteLine("余额不足!");
Menu();
}
else
{
Console.WriteLine("取款成功,帐号{0}的余额为:{1}", Getuser._account, Money);
}
}
}
//查询余额的操作输入方法
public void show()
{
Console.WriteLine("请输入要查询的帐号:");
string searchAccount = Console.ReadLine();
for (int i = 0; i < user.Length; i++)
{
if (searchAccount.Equals(user[i]._account))
{
Console.WriteLine("北大青鸟查询系统");
Console.WriteLine("帐号为:" + user[i]._account);
Console.WriteLine("账户姓名为:" + user[i]._name);
Console.WriteLine("余额为:" + user[i]._money);
Console.WriteLine("身份证号是:" + user[i]._idcard);
Menu();
}
else
{
Console.WriteLine("您输入的帐号不存在");
show();
}
}
}
//修改密码的输入方法
public void Xpassword()
{
Console.WriteLine("请输入要修改密码的帐号");
string XAccount = Console.ReadLine();
Console.WriteLine("请输入密码:");
string XPassword = Console.ReadLine();
Console.WriteLine("请输入新密码:");
string newpassword1 = Console.ReadLine();
Console.WriteLine("请再次输入新密码:");
string newpassword2 = Console.ReadLine();
Users XUser = CheckUser(XAccount, XPassword);
if (XUser == null)
{
Console.WriteLine("帐号或密码输入错误,请重新输入");
Xpassword();
}
els
e
{
if (newpassword1.Equals(newpassword2))
{
XUser._password = newpassword1;
Console.WriteLine("密码修改成功,修改后的密码为"+XUser._password);
}
else
{
Console.WriteLine("两次输入的密码不正确");
Xpassword();
}
}
}
//检查转出账户是否存在
public Users CheckUser(string account, string passsword)
{
for (int i = 0; i < user.Length; i++)
{
if (account.Equals(user[i]._account) && passsword.Equals(user[i]._password))
{
return user[i];
}
}
return null;
}
//检查转入帐号是否存在
public Users ChenkUserByAccount(string inputAccount)
{
Console.WriteLine("版权所有:徐也轩");
for (int i = 0; i < user.Length; i++)
{
if (inputAccount.Equals(user[i]._account))
{
return user[i];
}
}
return null;
}
//转账方法
public int Transfer(string account,string password,string inputAccount,double Money,ref double FromMoney,ref double ToMoney)
{
Users userFrom = CheckUser(account, password);
if (userFrom == null)
{
return -1; //转出账户密码不正确
}
Users userTo =ChenkUserByAccount(inputAccount);
if (userTo == null)
{
return -2; //转入账户帐号不正确
}
//调用Users类的取款方法
double i = userFrom.JianMoney(Money);
if (i == -3.0)
{
return -3;
}
FromMoney = i;
ToMoney = userTo.AddMoney(Money);
return 1;
}
}
}
测试类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankBank
{
class Program
{
static void Main(string[] args)
{
Bank bank = new Bank();
bank.initial();
bank.Menu();
Console.ReadLine();
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论