题目内容
程序填空题:(1)创建时间类,它包含的三个成员变量hour、minute、second,编写TimePeriod方法,用于计算零点时刻到当前时间的时间间隔(秒)。(2)创建实例,并按6个数位hh:mm:ss(2个表示小时,2个表示分钟、2个表示秒)输出相关信息,如:03:24:33 或 14:05:45。计算并显示对象与零点时刻的时间间隔。public class Timer{ private int hour; private int minute; private int second; public int getHour() { (1); } public void setHour(int hour) throws Exception { if (hour < 0(2) hour >= 24) { throw new Exception("输入的小时不合理"); } else { (3); } } public int getMinute() {(4); } public void setMinute(int minute) throws Exception { if (minute >= 0 && minute < 60) {(5); } else { throw new Exception("输入的分钟不合理"); } } public int getSecond() {(6) ; } public void setSecond(int second) throws Exception { if (second < 0 || second >= 60) { throw new Exception("输入的秒不合理"); } else {(7); } } public(8) (int hh,int mm,int ss) throws Exception { setHour(hh); setMinute(mm); setSecond(ss); }(9) timePeriod(){return hour * 3600 + minute * 60 + second; }}public class Program{ public static void main(String[] args) { try { Timer time1 = new Timer(22, 6, 15); System.out.printf("%d:%d:%d\n" , ____); System.out.println("零点时刻到当前时间的时间间隔:" + ____); }catch(Exception e) { System.out.println(); } }}
查看答案
搜索结果不匹配?点我反馈