程序设计题
请使用委托实现信用卡用户定时还款功能。
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
credituser c = new credituser(1000, 10000,9,10);
System.Timers.Timer atimer = new System.Timers.Timer();
atimer.Elapsed += new ElapsedEventHandler(c.dealdebt);
atimer.Interval = 10000;
atimer.Enabled = true;
Console.ReadKey();
}
}
class credituser
{
private double indebt;
private double save;
private int hour;
private int minute;
public credituser(double indebt,double save,int hour,int minute) {
this.indebt = indebt; this.save = save;
this.hour = hour; this.minute = minute;
}
public void debtandsave()
{
Console.WriteLine("debt:{0},save:{1}",this.indebt,this.save);
}
public void dealdebt(object source, ElapsedEventArgs e)
{
Console.WriteLine("进入定时监控程序......");
int intHour = e.SignalTime.Hour;
int intMinute = e.SignalTime.Minute;
if (this.hour==intHour && this.minute==intMinute)
{
this.indebt=this.indebt - 100<0?0:this.indebt-100;
save -= 100;
this.hour += 1;
Console.WriteLine("开始执行!");
debtandsave();
}
}
}
}
结果截图: