为什么下面的文字会出现2次?
1.存款
2.取款
3.查询余额
4.修改密码
5.退出
-----------------------------------------------
你的选择(回车结束):
1.存款
2.取款
3.查询余额
4.修改密码
5.退出
-----------------------------------------------
你的选择(回车结束):有4个类:
namespace ATM
{
class Start
{
static void Main(string[] args)
{
Bank bank = new Bank("交通银行");
Atm atm = new Atm(bank);
atm.Start();
}
}
}
namespace ATM
{
class Account
{
protected string name;
protected string password;
protected decimal balance; public Account(string name, string password)
{
this.name = name;
this.password = password;
this.balance = 0;
} public string Name
{
get
{
return name;
}
}
public decimal Balance
{
get
{
return balance;
}
} public bool Deposit(decimal amount)
{
if (amount <= 0)
{
return false;
}
balance += amount;
return true;
}
public bool Deposit(double amount)
{
return Deposit((decimal)amount);
}
public bool Deposit(int amount)
{
return Deposit((decimal)amount);
}
public bool Deposit(decimal amount, out decimal balance)
{
bool succeed = Deposit(amount);
balance = this.balance;
return succeed;
} public bool Withdraw(decimal amount)
{
if (amount > balance || amount <= 0)
{
return false;
}
balance -= amount;
return true;
}
public bool Withdraw(double amount)
{
return Withdraw((decimal)amount);
}
public bool Withdraw(int amount)
{
return Withdraw((decimal)amount);
}
public bool Withdraw(decimal amount, out decimal balance)
{
bool succeed = Withdraw(amount);
balance = this.balance;
return succeed;
} public bool Login(string name, string password)
{
return (this.name == name && this.password == password);
} public bool ChangePassword(string oldPassword, string newPassword)
{
if (password != oldPassword)
{
return false;
}
password = newPassword;
return true;
}
}
}
namespace ATM
{
class Bank
{
protected const int MaxAccountNum = 2048;
protected string name;
protected int usedAccountNum;
protected Account[] accounts; public Bank(string name)
{
this.name = name;
this.usedAccountNum = 0;
accounts = new Account[MaxAccountNum];
} public string Name
{
get
{
return name;
}
} public bool LoginAccount(string name, string password, out Account account)
{
account = null;
for (int i = 0; i < usedAccountNum; i++)
{
if (accounts[i].Login(name, password))
{
account = accounts[i];
return true;
}
}
return false;
} public bool OpenAccount(string name, string password, out Account account)
{
account = null;
for (int i = 0; i < usedAccountNum; i++)
{
if (accounts[i].Name == name)
return false;
}
account = new Account(name, password);
accounts[usedAccountNum++] = account;
return true;
}
}
}
1.存款
2.取款
3.查询余额
4.修改密码
5.退出
-----------------------------------------------
你的选择(回车结束):
1.存款
2.取款
3.查询余额
4.修改密码
5.退出
-----------------------------------------------
你的选择(回车结束):有4个类:
namespace ATM
{
class Start
{
static void Main(string[] args)
{
Bank bank = new Bank("交通银行");
Atm atm = new Atm(bank);
atm.Start();
}
}
}
namespace ATM
{
class Account
{
protected string name;
protected string password;
protected decimal balance; public Account(string name, string password)
{
this.name = name;
this.password = password;
this.balance = 0;
} public string Name
{
get
{
return name;
}
}
public decimal Balance
{
get
{
return balance;
}
} public bool Deposit(decimal amount)
{
if (amount <= 0)
{
return false;
}
balance += amount;
return true;
}
public bool Deposit(double amount)
{
return Deposit((decimal)amount);
}
public bool Deposit(int amount)
{
return Deposit((decimal)amount);
}
public bool Deposit(decimal amount, out decimal balance)
{
bool succeed = Deposit(amount);
balance = this.balance;
return succeed;
} public bool Withdraw(decimal amount)
{
if (amount > balance || amount <= 0)
{
return false;
}
balance -= amount;
return true;
}
public bool Withdraw(double amount)
{
return Withdraw((decimal)amount);
}
public bool Withdraw(int amount)
{
return Withdraw((decimal)amount);
}
public bool Withdraw(decimal amount, out decimal balance)
{
bool succeed = Withdraw(amount);
balance = this.balance;
return succeed;
} public bool Login(string name, string password)
{
return (this.name == name && this.password == password);
} public bool ChangePassword(string oldPassword, string newPassword)
{
if (password != oldPassword)
{
return false;
}
password = newPassword;
return true;
}
}
}
namespace ATM
{
class Bank
{
protected const int MaxAccountNum = 2048;
protected string name;
protected int usedAccountNum;
protected Account[] accounts; public Bank(string name)
{
this.name = name;
this.usedAccountNum = 0;
accounts = new Account[MaxAccountNum];
} public string Name
{
get
{
return name;
}
} public bool LoginAccount(string name, string password, out Account account)
{
account = null;
for (int i = 0; i < usedAccountNum; i++)
{
if (accounts[i].Login(name, password))
{
account = accounts[i];
return true;
}
}
return false;
} public bool OpenAccount(string name, string password, out Account account)
{
account = null;
for (int i = 0; i < usedAccountNum; i++)
{
if (accounts[i].Name == name)
return false;
}
account = new Account(name, password);
accounts[usedAccountNum++] = account;
return true;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货