using
System;
using
System.Collections.Generic;
namespace
card_work
{
undefined
class
depositCard
{
undefined
//储蓄名
private
string
name;
//储蓄金额
private
int
depositMoney;
//基础储蓄金额
public
depositCard
(
string
name,
int
money)
{
undefined
this
.name = name;
this
.depositMoney = money;
}
//获取储蓄金额
public
int
getDepositMoney()
{
undefined
return
this
.depositMoney;
}
public
void
setDepositMoney(
int
r)
{
undefined
this
.depositMoney = r;
}
}
//信用卡类
class
creditCard
{
undefined
//信用卡持有者名称
public
string
name;
//信用卡余额
public
int
creditMoney;
//扣款日期
public
int
dueDay;
//绑定储蓄卡对象
public
depositCard DC;
//初始化
public
creditCard
(
string
name,
int
CM,
int
DD, depositCard DC)
{
undefined
this
.name = name;
this
.creditMoney = CM;
this
.dueDay = DD;
this
.DC = DC;
}
//还款
public
void
repayM()
{
undefined
Console.WriteLine(“用户{ 0}
当前金额{ 1}”,
this
.name,
this
.DC.getDepositMoney());
DC.setDepositMoney(
this
.DC.getDepositMoney() + creditMoney);
Console.WriteLine(“用户已还款”);
Console.WriteLine(“还款金额:{ 0}”, Math.Abs(
this
.creditMoney));
Console.WriteLine(“余下金额为{ 0}”, DC.getDepositMoney());
Console.WriteLine();
}
//无需还款
public
void
norepayM()
{
undefined
Console.WriteLine(“用户{ 0}
当前金额{ 1}”,
this
.nane,
this
.DC.getDepositMoney());
Console.WriteLine(“用户未到还款日期,无需还款”,
this
.name);
Console.WriteLine();
}
}
//扣款委托类
class
repayDelegate
{
undefined
//扣款委托
public
delegate
void
repayMoney
();
//扣款事件
public
event
repayMoney DoRepay;
//事件执行
public
void
NotifyRepay()
{
undefined
if
(DoRepay !=
null
)
{
undefined
Console.WriteLine(“触发事件:”);
DoRepay();
}
}
}
class
Program
{
undefined
static
void
Main(
string
[] args)
{
undefined
depositCard D1 =
new
depositCard(“张三”, 10000);
depositCard D2 =
new
depositCard(“李四”, 10000);
depositCard D3 =
new
depositCard(“王五”, 10000);
creditCard C1 =
new
creditCard(“张三”, -5000, 5, D1);
creditCard C2 =
new
creditCard(“李四”, -3000, 31, D2);
creditCard C3 =
new
creditCard(“王五”, -1000, 5, D3);
List cCards =
new
List();
cCards.Add(C1);
cCards.Add(C2);
cCards.Add(C3);
//创建委托对象
repayDelegate rD =
new
repayDelegate();
foreach
(creditCard C
in
cCards)
{
//判断是否到了该还款的日期
if
(C.dueDay ==
int
.Parse(DateTime.Now.ToString(
“yyyy-MM-dd”
).Split(
‘-‘
)[2]))
{
//事件添加
rD.DoRepay +=
new
repayDelegate.repayMoney(C.repayM);
}
else
{
rD.DoRepay +=
new
repayDelegate.repayMoney(C.norepayM);
}
}
//事件执行
rD.NotifyRepay();
}
}
https://gitee.com/Jasonnoon/jasonnoon.git