类设计
银行卡共有储蓄卡(Account)与信用卡(Credit)两种

在银行类(bank)中添加Account类的成员,ATM类要实现银行的业务,BankDemo用于编写main方法测试功能。

源码
BankDemo类:
using System;
namespace BankDemo
{
public class BankDemo {
public static void Main(string[] args) {
Bank bank = new Bank();
// 插入初始数据
bank.OpenAccount("2222", "2222", 20);
bank.OpenAccount("3333", "3333", 50);
bank.OpenCredit("4444","4444",100,1000);
ATM atm = new ATM(bank);
bool login_ctr = false; // 用于控制登录逻辑
bool service_ctr = true; // 用于控制业务逻辑
while (!login_ctr)
{
Account account = atm.Login();
if (account == null) // 登录失败
{
Console.WriteLine("card invalid or password not corrent,please retry again");
service_ctr = false;
}
else // 登录成功
{
service_ctr = true; // 可以开始业务
}
while (service_ctr)
{
//login_ctr = true; // 登录成功
service_ctr = atm.Transaction(account);
}
Console.ReadKey(); // 停顿一下
Console.Clear(); // 清屏
}
}
}
}
Account类:
using System;
using System.Collections.Generic;
using System.Text;
namespace BankDemo
{
public class Account
{
protected double _money; //decimal money;
protected string _id;
protected string _pwd; //string name;
public Account(string id, string pwd, double money)
{
//if( money < 0 ) throw new Exception("....");
Id = id;
Pwd = pwd;
Money = money;
}
public Account() {
}
public double Money
{
set {
_money = value;


8095

被折叠的 条评论
为什么被折叠?



