using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bank
{
class BankMethods
{
//创建一个对象组
BankMethods[] banker =new BankMethods[4];
BankMethods[] banker2 = new BankMethods[1];
//名字
private string _name;
public string Name
{
get { return _name; }
set { this._name = value; }
}
//卡号
private string _id;
public string Id
{
get { return _id; }
set { this._id = value; }
}
//名字
private string _pwd;
public string Pwd
{
get { return _pwd; }
set { this._pwd = value; }
}
//余额
private double _balance;
public double Balance
{
get { return _balance; }
set { this._balance = value; }
}
//创建一个老用户的方法
public void Bank()
{
banker[0] = new BankMethods() { Name = "小红", Id = "123456", Pwd = "123", Balance = 500 };
banker[1] = new BankMethods() { Name = "小明", Id = "123467", Pwd ="123", Balance = 600 };
banker[2] = new BankMethods() { Name = "小黑", Id = "123458", Pwd = "123", Balance = 700 };
banker[3] = new BankMethods() { Name = "小王", Id = "123469", Pwd = "123", Balance = 800 };
foreach (BankMethods b in banker) {
b.say();
}
}
//遍历出这些银行老用户
public void say() {
Console.WriteLine("名字是{0},卡号是{1},密码是{2},余额是{3}", this._name, this._id,this._pwd, this._balance);
}
//创建一个余额增加的方法
public void Increase(double NewMoney) {
if (NewMoney > 0) {
this._balance += NewMoney;
}
}
//创建一个余额减少的方法
public void Reduce(double NewMoney) {
if (NewMoney <= this._balance && NewMoney > 0) {
this._balance -= NewMoney;
}
}
//打印提示
public int Print() {
Console.WriteLine("====================================================");
Console.WriteLine("==========欢迎进入自助银行系统==========");
Console.WriteLine("请选择:1.转账 2.存款 3.取款 4.查询余额 5.开户 6.退出");
Console.WriteLine("====================================================");
int result = int.Parse(Console.ReadLine());
return result;
}
//判断卡号和密码是否正确
public BankMethods Judge(string id,string pwd) {
foreach (BankMethods judge in banker) {
if (judge.Id.Equals(id) && judge.Pwd.Equals(pwd)) {
return judge;
}
}
foreach (BankMethods judge2 in banker2)
{
if (judge2.Id.Equals(id) && judge2.Pwd.Equals(pwd))
{
return judge2;
}
}
return null;
}
//判断卡号是否正确
public BankMethods Judge2(string id)
{
foreach (BankMethods jude in banker)
{
if (jude.Id.Equals(id))
{
return jude;
}
}
foreach (BankMethods jude2 in banker2)
{
if (jude2.Id.Equals(id))
{
return jude2;
}
}
return null;
}
//开户
public void OpenBank() {
Console.WriteLine("请输入名字");
string name = Console.ReadLine();
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
Console.WriteLine("请输入存款金额");
double balance = double.Parse(Console.ReadLine());
Increase(balance);
string id = "666666";
this._name = name; this._pwd = pwd; this._id = id; this._balance = balance;
Console.WriteLine("开户成功!你的名字是{0},卡号是{1},密码是{2},余额是{3}", this._name, this._id, this._pwd, this._balance);
banker2[0] = new BankMethods() { Name=name,Id=id,Pwd=pwd,Balance=balance};
}
//取钱
public void DrawMoney() {
Console.WriteLine("请输入卡号");
string id = Console.ReadLine();
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
BankMethods b = Judge(id, pwd);
if (b == null)
{
Console.WriteLine("输入卡号或密码错误");
}
else {
Console.WriteLine("请输入取款金额");
double money = double.Parse(Console.ReadLine());
b.Reduce(money);
Console.WriteLine("取款成功!余额为:" + b.Balance);
}
}
//存钱
public void Deposit() {
Console.WriteLine("请输入卡号");
string id = Console.ReadLine();
BankMethods b = Judge2(id);
if (b == null)
{
Console.WriteLine("此卡号不存在");
}
else {
Console.WriteLine("请输入存款金额");
double money = double.Parse(Console.ReadLine());
b.Increase(money);
Console.WriteLine("存款成功");
}
}
//转账
public void Transfer() {
Console.WriteLine("请输入转账人卡号");
string id = Console.ReadLine();
Console.WriteLine("请输入转账人密码");
string pwd = Console.ReadLine();
BankMethods b = Judge(id, pwd);
if (b == null)
{
Console.WriteLine("输入错误");
}
else {
Console.WriteLine("请输入收账人卡号");
string id2 = Console.ReadLine();
BankMethods b2 = Judge2(id2);
if (b2 == null)
{
Console.WriteLine("输入错误");
}
else {
Console.WriteLine("请输入转账金额");
double money = double.Parse(Console.ReadLine());
b.Reduce(money);
b2.Increase(money);
Console.WriteLine("转账成功!!!");
}
}
}
//查询余额
public void Balances() {
Console.WriteLine("请输入卡号");
string id = Console.ReadLine();
Console.WriteLine("请输入密码");
string pwd = Console.ReadLine();
BankMethods b = Judge(id, pwd);
if (b == null)
{
Console.WriteLine("输入错误");
}
else {
Console.WriteLine("您的余额为:" + b.Balance);
}
}
}
class Program
{
static void Main(string[] args)
{
//1.转账 2.存款 3.取款 4.查询余额 5.开户 6.退出
BankMethods bank = new BankMethods();
bank.Bank();
do
{
switch (bank.Print())
{
case 1:
bank.Transfer();
continue;
case 2:
bank.Deposit();
continue;
case 3:
bank.DrawMoney();
continue;
case 4:
bank.Balances();
continue;
case 5:
bank.OpenBank();
continue;
case 6:
break;
}
break;
} while (1 == 1);
}
}
}