银行账户类 累
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankSystem
{
// 为银行开发应用系统。银行账户Account,包含信息有账号、户主姓名、余额Balance,对账户的操作有取款,存款,查询余额。
//账户又分为储蓄账户SavingAccount和信用卡账户CreditAccount。
//储蓄账户有利息,利率是3.5% ,取款时不能透支。
//信用卡账户没有利息,有透支额度。
//账户可以订制余额变动通知服务,在余额变化后,用短信或邮件通知用户。
//按以上信息
//1 设计类BankAccount,完成构造取款存款查询等方法。(20’)
//2 使用继承,完成SavingAccount,CreditAccount类(30‘)
//3 将(1)完成的代码注释,将BankAccount 类改为抽象类,取款,存款方法改为抽象方法。(20’)
//4 定义余额变动事件,在余额改变时触发。(20)
//5 在Program类的Main方法里,应用你定义的类。如:
// 创建一个储蓄账户
// 创建一个信用卡账户
// 存取款
// 查余额
// 为账户余额变动事件写处理方法,在控制台输入提示信息。
//class BankAccount
//{
// private string accountNO;//账号
// public string AccountNO
// {
// get { return accountNO; }
// }
// private string name;//户主姓名
// public string Name
// {
// get { return name; }
// }
// protected decimal balance;//余额Balance
// public decimal Balance
// {
// get { return balance; }
// }
// public BankAccount(string accountNO,string name,decimal balance)
// {
// this.accountNO = accountNO;
// this.name = name;
// this.balance = balance;
// }
// public void Deposit(decimal money) //存款
// {
// balance += money;
// }
// public virtual void Teller(decimal money) //取款
// {
// if (balance >= money)
// {
// balance -= money;
// }
// }
// public void DispInfo()
// {
// Console.WriteLine("{0} {1} {2}", AccountNO, Name, Balance);
// }
//}
delegate void MyDelegate(BankAccount ba ,decimal change);
abstract class BankAccount
{
public event MyDelegate handleBalanceChange;
private string accountNO;//账号
public string AccountNO
{
get { return accountNO; }
}
private string name;//户主姓名
public string Name
{
get { return name; }
}
protected decimal balance;//余额Balance
protected decimal Balance
{
get { return balance; }
set
{
decimal change = value - balance;
balance = value;
if (handleBalanceChange != null)
{
handleBalanceChange(this, change);
}
}
}
public BankAccount(string accountNO, string name, decimal balance)
{
this.accountNO = accountNO;
this.name = name;
this.balance = balance;
}
public abstract void Deposit(decimal money);
public abstract void Teller(decimal money);
public virtual void DispInfo()
{
Console.WriteLine("{0} {1} {2}", AccountNO, Name, Balance);
}
}
class SavingAccount : BankAccount
{
public SavingAccount(string accountNO, string name, decimal balance)
: base(accountNO, name, balance)
{
}
float interestRate = 0.035f;
public float InterestRate
{
get { return interestRate; }
set { interestRate = value; }
}
public override void Deposit(decimal money) //存款
{
Balance += money;
}
public override void Teller(decimal money) //取款
{
if (Balance >= money)
{
Balance -= money;
}
}
public override void DispInfo()
{
Console.WriteLine("{0} {1} {2} interestRate:{3} ", AccountNO, Name, Balance, interestRate);
}
}
class CreditAccount : BankAccount
{
public CreditAccount(string accountNO, string name, decimal balance)
: base(accountNO, name, balance)
{
}
decimal overdraftFacility=10000;
public decimal OverdraftFacility
{
get { return overdraftFacility; }
set { overdraftFacility = value; }
}
public override void Deposit(decimal money) //存款
{
Balance += money;
}
public override void Teller(decimal money) //取款
{
if ((Balance + overdraftFacility) >= money)
{
Balance -= money;
}
}
public override void DispInfo()
{
Console.WriteLine("{0} {1} {2} overdraftFacility:{3} ", AccountNO, Name, Balance, overdraftFacility);
}
}
class Program
{
static void Main(string[] args)
{
SavingAccount sa = new SavingAccount("s001","zhanghua",54020);
CreditAccount ca = new CreditAccount("c001", "wangfang", 45564);
sa.handleBalanceChange += new MyDelegate(sa_handleBalanceChange);
ca.handleBalanceChange += new MyDelegate(sa_handleBalanceChange);
sa.Teller(5000);
sa.Deposit(8000);
ca.Teller(3000);
ca.Deposit(8000);
}
static void sa_handleBalanceChange(BankAccount ba ,decimal change)
{
Console.WriteLine("你账户增加了{0}元",change);
Console.WriteLine("你更新后的账户信息");
ba.DispInfo();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankSystem
{
// 为银行开发应用系统。银行账户Account,包含信息有账号、户主姓名、余额Balance,对账户的操作有取款,存款,查询余额。
//账户又分为储蓄账户SavingAccount和信用卡账户CreditAccount。
//储蓄账户有利息,利率是3.5% ,取款时不能透支。
//信用卡账户没有利息,有透支额度。
//账户可以订制余额变动通知服务,在余额变化后,用短信或邮件通知用户。
//按以上信息
//1 设计类BankAccount,完成构造取款存款查询等方法。(20’)
//2 使用继承,完成SavingAccount,CreditAccount类(30‘)
//3 将(1)完成的代码注释,将BankAccount 类改为抽象类,取款,存款方法改为抽象方法。(20’)
//4 定义余额变动事件,在余额改变时触发。(20)
//5 在Program类的Main方法里,应用你定义的类。如:
// 创建一个储蓄账户
// 创建一个信用卡账户
// 存取款
// 查余额
// 为账户余额变动事件写处理方法,在控制台输入提示信息。
//class BankAccount
//{
// private string accountNO;//账号
// public string AccountNO
// {
// get { return accountNO; }
// }
// private string name;//户主姓名
// public string Name
// {
// get { return name; }
// }
// protected decimal balance;//余额Balance
// public decimal Balance
// {
// get { return balance; }
// }
// public BankAccount(string accountNO,string name,decimal balance)
// {
// this.accountNO = accountNO;
// this.name = name;
// this.balance = balance;
// }
// public void Deposit(decimal money) //存款
// {
// balance += money;
// }
// public virtual void Teller(decimal money) //取款
// {
// if (balance >= money)
// {
// balance -= money;
// }
// }
// public void DispInfo()
// {
// Console.WriteLine("{0} {1} {2}", AccountNO, Name, Balance);
// }
//}
delegate void MyDelegate(BankAccount ba ,decimal change);
abstract class BankAccount
{
public event MyDelegate handleBalanceChange;
private string accountNO;//账号
public string AccountNO
{
get { return accountNO; }
}
private string name;//户主姓名
public string Name
{
get { return name; }
}
protected decimal balance;//余额Balance
protected decimal Balance
{
get { return balance; }
set
{
decimal change = value - balance;
balance = value;
if (handleBalanceChange != null)
{
handleBalanceChange(this, change);
}
}
}
public BankAccount(string accountNO, string name, decimal balance)
{
this.accountNO = accountNO;
this.name = name;
this.balance = balance;
}
public abstract void Deposit(decimal money);
public abstract void Teller(decimal money);
public virtual void DispInfo()
{
Console.WriteLine("{0} {1} {2}", AccountNO, Name, Balance);
}
}
class SavingAccount : BankAccount
{
public SavingAccount(string accountNO, string name, decimal balance)
: base(accountNO, name, balance)
{
}
float interestRate = 0.035f;
public float InterestRate
{
get { return interestRate; }
set { interestRate = value; }
}
public override void Deposit(decimal money) //存款
{
Balance += money;
}
public override void Teller(decimal money) //取款
{
if (Balance >= money)
{
Balance -= money;
}
}
public override void DispInfo()
{
Console.WriteLine("{0} {1} {2} interestRate:{3} ", AccountNO, Name, Balance, interestRate);
}
}
class CreditAccount : BankAccount
{
public CreditAccount(string accountNO, string name, decimal balance)
: base(accountNO, name, balance)
{
}
decimal overdraftFacility=10000;
public decimal OverdraftFacility
{
get { return overdraftFacility; }
set { overdraftFacility = value; }
}
public override void Deposit(decimal money) //存款
{
Balance += money;
}
public override void Teller(decimal money) //取款
{
if ((Balance + overdraftFacility) >= money)
{
Balance -= money;
}
}
public override void DispInfo()
{
Console.WriteLine("{0} {1} {2} overdraftFacility:{3} ", AccountNO, Name, Balance, overdraftFacility);
}
}
class Program
{
static void Main(string[] args)
{
SavingAccount sa = new SavingAccount("s001","zhanghua",54020);
CreditAccount ca = new CreditAccount("c001", "wangfang", 45564);
sa.handleBalanceChange += new MyDelegate(sa_handleBalanceChange);
ca.handleBalanceChange += new MyDelegate(sa_handleBalanceChange);
sa.Teller(5000);
sa.Deposit(8000);
ca.Teller(3000);
ca.Deposit(8000);
}
static void sa_handleBalanceChange(BankAccount ba ,decimal change)
{
Console.WriteLine("你账户增加了{0}元",change);
Console.WriteLine("你更新后的账户信息");
ba.DispInfo();
}
}
}