using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Intrinsics.X86;
namespace ConsoleApp2
{
public class BankException : ApplicationException
{
public BankException()
{
}
public BankException(string message) : base(message)
{
}
public BankException(string message,Exception inner) : base(message, inner)
{
}
}
public interface GeneralATM
{
void Transaction(CreditBank bank);
}
public class ATM :GeneralATM
{
Bank bank;
public ATM(Bank bank)
{
this.bank = bank;
}
public void Transaction(CreditBank bank)
{
Show("这里是"+bank.bankname);
Show("请输入您的卡号"); //输入卡号
string id = GetInput();
Show("请输入您的密码"); //输入密码
string pwd = GetInput();
CreditAccount act=null;
foreach (CreditAccount account in bank.creditaccounts)
{
if (account.id == id && account.pwd==pwd) act = account;
};
if (act == null)
{
try
{
throw new BankException("卡号或密码错误");//卡号或密码错误
}
catch (BankException b)
{
Console.WriteLine(b.Message);
}
return;
}
Show("1: 查询余额; 2: 存钱; 3: 取钱");//成功登录,有三个选项对应三个功能
string op = GetInput();
if (op == "1")
{
Show("余额: " + act.getMoney());//显示当前账户余额
}
else if (op == "2")
{
Show("请输入想存的钱数");//给当前用户存钱
string smoney = GetInput();
double money = double.Parse(smoney);
bool ok = act.SaveMoney(money);
if (ok) Show("操作成功");
else Show("eeer");
Show("余额: " + act.getMoney());
}
else if (op == "3") //从当前用户取钱
{
Show("请输入想取的钱数");
string smoney = GetInput();
double money = double.Parse(smoney);
bool ok = act.WithdrawMoney(money);
if (ok) Show("操作成功");//当取钱金额大于余额时,报错
else Show("eeer");
Show("余额: " + act.getMoney());
}
}
public void Show(string msg)
{
Console.WriteLine(msg);
}
public string GetInput()
{
return Console.ReadLine();// 输入字符
}
}
//--------------账号类--------------------
public class Account
{
double money; //decimal money;
public string id;
public string pwd;
//string name;
public Account(string id, string pwd, double money)
{
this.id = id;//账号
this.pwd = pwd;//密码
this.money = money;//余额
}
public double getMoney()
{
return money;
}
public void setMoney(double val)
{
this.money = val;
}
public string getId()
{
return id;
}
public void setId(string id)
{
this.id = id;
}
public string getpwd()
{
return pwd;
}
public void setPwd(string pwd)
{
this.pwd = pwd;
}
public bool SaveMoney(double money)
{
if (money < 0) return false; //卫语句
this.money += money;
return true;
}
public bool WithdrawMoney(double money)//取钱方法
{
if (this.money >= money)
{
this.money -= money;
return true;
}
return false;
}
public bool IsMatch(string id, string pwd)
{
return id == this.id && pwd == this.pwd;
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Intrinsics.X86;
namespace ConsoleApp2
{
public class BankException : ApplicationException
{
public BankException()
{
}
public BankException(string message) : base(message)
{
}
public BankException(string message,Exception inner) : base(message, inner)
{
}
}
public interface GeneralATM
{
void Transaction(CreditBank bank);
}
public class ATM :GeneralATM
{
Bank bank;
public ATM(Bank bank)
{
this.bank = bank;
}
public void Transaction(CreditBank bank)
{
Show("这里是"+bank.bankname);
Show("请输入您的卡号"); //输入卡号
string id = GetInput();
Show("请输入您的密码"); //输入密码
string pwd = GetInput();
CreditAccount act=null;
foreach (CreditAccount account in bank.creditaccounts)
{
if (account.id == id && account.pwd==pwd) act = account;
};
if (act == null)
{
try
{
throw new BankException("卡号或密码错误");//卡号或密码错误
}
catch (BankException b)
{
Console.WriteLine(b.Message);
}
return;
}
Show("1: 查询余额; 2: 存钱; 3: 取钱");//成功登录,有三个选项对应三个功能
string op = GetInput();
if (op == "1")
{
Show("余额: " + act.getMoney());//显示当前账户余额
}
else if (op == "2")
{
Show("请输入想存的钱数");//给当前用户存钱
string smoney = GetInput();
double money = double.Parse(smoney);
bool ok = act.SaveMoney(money);
if (ok) Show("操作成功");
else Show("eeer");
Show("余额: " + act.getMoney());
}
else if (op == "3") //从当前用户取钱
{
Show("请输入想取的钱数");
string smoney = GetInput();
double money = double.Parse(smoney);
bool ok = act.WithdrawMoney(money);
if (ok) Show("操作成功");//当取钱金额大于余额时,报错
else Show("eeer");
Show("余额: " + act.getMoney());
}
}
public void Show(string msg)
{
Console.WriteLine(msg);
}
public string GetInput()
{
return Console.ReadLine();// 输入字符
}
}
//--------------账号类--------------------
public class Account
{
double money; //decimal money;
public string id;
public string pwd;
//string name;
public Account(string id, string pwd, double money)
{
this.id = id;//账号
this.pwd = pwd;//密码
this.money = money;//余额
}
public double getMoney()
{
return money;
}
public void setMoney(double val)
{
this.money = val;
}
public string getId()
{
return id;
}
public void setId(string id)
{
this.id = id;
}
public string getpwd()
{
return pwd;
}
public void setPwd(string pwd)
{
this.pwd = pwd;
}
public bool SaveMoney(double money)
{
if (money < 0) return false; //卫语句
this.money += money;
return true;
}
public bool WithdrawMoney(double money)//取钱方法
{
if (this.money >= money)
{
this.money -= money;
return true;
}
return false;
}
public bool IsMatch(string id, string pwd)
{
return id == this.id && pwd == this.pwd;
}
}