程序填空题:
(1)创建时间类,它包含的三个成员变量hour、minute、second,编写TimePeriod方法,用于计算零点时刻到当前时间的时间间隔(秒)。
(2)创建实例,并按6个数位hh:mm:ss(2个表示小时,2个表示分钟、2个表示秒)输出相关信息,如:03:24:33 或 14:05:45。计算并显示对象与零点时刻的时间间隔。
class Timer
{
private int hour;
public int Hour
{
get { 【1】 ; }
set
{
if (value < 0 【2】 value >= 24)
{
throw new Exception("输入的小时不合理");
}
else
{
【3】 _;
}
}
}
private int minute;
public int Minute
{
get { 【4】 ; }
set
{
if (value >=0 && value < 60)
{
【5】 ;
}
else
{
throw new Exception("输入的分钟不合理");
}
}
}
private int second;
public int Second
{
get { 【6】 ; }
set
{
if (value >=0 && value < 60)
{
【7】 ;
}
else
{
throw new Exception("输入的秒不合理");
}
}
}
public 【8】 (int hh,int mm,int ss)
{
Hour = hh;
Minute = mm;
Second = ss;
}
【9】
{
return hour * 3600 + minute * 60 + second;
}
}
class Program
{
static void Main(string[] args)
{
try
{
Timer time1 = new Timer(22, 6, 15);
Console.WriteLine("{0:d2}:{1:d2}:{2:d2}",_ 【10】 );
Console.WriteLine("零点时刻到当前时间的时间间隔:{0}", 【11】 );
}
【12】
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
}
(1)创建时间类,它包含的三个成员变量hour、minute、second,编写TimePeriod方法,用于计算零点时刻到当前时间的时间间隔(秒)。
(2)创建实例,并按6个数位hh:mm:ss(2个表示小时,2个表示分钟、2个表示秒)输出相关信息,如:03:24:33 或 14:05:45。计算并显示对象与零点时刻的时间间隔。
class Timer
{
private int hour;
public int Hour
{
get { 【1】 ; }
set
{
if (value < 0 【2】 value >= 24)
{
throw new Exception("输入的小时不合理");
}
else
{
【3】 _;
}
}
}
private int minute;
public int Minute
{
get { 【4】 ; }
set
{
if (value >=0 && value < 60)
{
【5】 ;
}
else
{
throw new Exception("输入的分钟不合理");
}
}
}
private int second;
public int Second
{
get { 【6】 ; }
set
{
if (value >=0 && value < 60)
{
【7】 ;
}
else
{
throw new Exception("输入的秒不合理");
}
}
}
public 【8】 (int hh,int mm,int ss)
{
Hour = hh;
Minute = mm;
Second = ss;
}
【9】
{
return hour * 3600 + minute * 60 + second;
}
}
class Program
{
static void Main(string[] args)
{
try
{
Timer time1 = new Timer(22, 6, 15);
Console.WriteLine("{0:d2}:{1:d2}:{2:d2}",_ 【10】 );
Console.WriteLine("零点时刻到当前时间的时间间隔:{0}", 【11】 );
}
【12】
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
}