using System;
namespace ConsoleApp3
{
class project
{
int 余额 = 10000;
信用 x;
public project(信用 x)
{
this.x = x;
}
public void 扣款操作()
{
if (x.检验是否还款() == 1)
{
余额 = 余额 - x.获取待还款金额();
if (余额<0)
Console.WriteLine("还款不成功,你的余额为:{0}", 余额);
else
Console.WriteLine("还款成功,你的余额为:{0}", 余额);
}
else
{
Console.WriteLine("尚不需要还款,你的余额为:{0}", 余额);
}
}
}
class 信用
{
int 还款日 = 28;
int 待还款金额;
int 还款的日期;
public 信用(int 还款金额, int 还款日期)
{
this.待还款金额 = 还款金额;
this.还款的日期 = 还款日期;
}
public int 获取待还款金额()
{
return 待还款金额;
}
public int 检验是否还款()
{
if (还款日 == 还款的日期)
return 1;
else
return 0;
}
}
class Delegate
{
public delegate void pay();
public event pay payment;
public void Notify()
{
if (payment != null)
{
Console.WriteLine("开始订阅:");
payment();
}
}
}
class Program
{
static void Main(string[] args)
{
Delegate objDelegate = new Delegate();
信用 x1 = new 信用(11000, 28);
信用 x3 = new 信用(2000, 28);
信用 x2 = new 信用(1000, 27);
project c1 = new project(x1);
project c3 = new project(x3);
project c2 = new project(x2);
objDelegate.payment +=
new Delegate.pay(c1.扣款操作);
objDelegate.payment +=
new Delegate.pay(c2.扣款操作);
objDelegate.payment +=
new Delegate.pay(c3.扣款操作);
objDelegate.Notify();
}
}
}
小结:通过这次作业我对委托有了进一步的了解,尽管在作业中对委托的处理出先了许多错误,但经过多次修改,最终得出了正确结果。
gitee仓库地址:https://gitee.com/zhu-yujie123/project1.git