题目内容:
这一周的编程题是需要你在课程所给的时钟程序的基础上修改而成。但是我们并不直接给你时钟程序的代码,请根据视频自己输入时钟程序的Display和Clock类的代码,然后来做这个题目。
我们需要给时钟程序加上一个表示秒的Display,然后为Clock增加以下public的成员函数:
1 2 3 4 5 6 7 |
public Clock(int hour, int minute, int second); ????用hour, minute和second初始化时间。 public void tick();? ???“嘀嗒”一下,时间走1秒。 public String toString(); 返回一个String的值,以“hh:mm:ss“的形式表示当前时间。这里每个数值都占据两位,不足两位时补0。如“00:01:22"。注意其中的冒号是西文的,不是中文的。 |
提示:String.format()可以用和printf一样的方式来格式化一个字符串。
另外写一个Main类,它的main函数为下面的样子,注意,必须原封不动地作为Main的main函数:
1 2 3 4 5 6 7 |
public?static?void?main(String[]?args) { java.util.Scanner?in?=?new?java.util.Scanner(System.in); Clock?clock?=?new?Clock(in.nextInt(),?in.nextInt(),?in.nextInt()); clock.tick(); System.out.println(clock); in.close(); } |
注意!在提交的时候,把Main、Clock和Display三个类的代码合并在一起,其中Main类是public的,而Clock和Display类是没有修饰符的。另外,千万注意第一行不能有package语句。
输入格式:
采用给定的main函数无需考虑输入输出。
输出格式:
采用给定的main函数无需考虑输入输出。
输入样例:
采用给定的main函数无需考虑输入输出。
输出样例:
采用给定的main函数无需考虑输入输出。
时间限制:500ms内存限制:32000kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
//梁笔记 //https://zouzhongliang.com class Display{ private int value =0; private int limit = 0; public Display(int limit) { this.limit = limit; } public boolean increase() { boolean Res= false; value++; if (value>=limit){ value =0; Res = true; } return Res; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } } class Clock{ private Display Hour = new Display(24); private Display Minute = new Display(60); private Display Seconds = new Display(60); public Clock(int Hour,int Minute,int Seconds) { this.Hour.setValue(Hour); this.Minute.setValue(Minute); this.Seconds.setValue(Seconds); } public void tick() { if (Seconds.increase()) { if(Minute.increase()) { Hour.increase(); } } } public String toString() { return String.format("%02d:%02d:%02d",Hour.getValue(),Minute.getValue(),Seconds.getValue()); } } public class Main{ public static void main(String[] args) { java.util.Scanner in = new java.util.Scanner(System.in); Clock clock = new Clock(in.nextInt(), in.nextInt(), in.nextInt()); clock.tick(); System.out.println(clock); in.close(); } } |
Appreciate it! Lots of advice.
fluconazol
You made the point! diflucan
Nicely put. Thank you. viagra before and after photos
Thank you. I enjoy it. price pro pharmacy canada
Information clearly applied.! https://viagradocker.com/
You actually reported this wonderfully. generic viagra online
Regards! An abundance of material!
viagra 100mg
Superb postings, Regards. buy viagra
Seriously plenty of superb facts. cephalexin 500mg
Thanks a lot. Great stuff. north west pharmacy canada
Whoa loads of fantastic material. canada pharmaceuticals online
You actually revealed it superbly! methocarbamol 500 mg
Nicely put, With thanks. is cbd oil legal in georgia
Really a lot of awesome information. valtrex 500 mg
Position well applied.! no 1 canadian pharcharmy online
You definitely made the point! buy generic viagra
Wow all kinds of good knowledge. viagra without a doctor prescription
You expressed it terrifically! metronidazole bnf
Nicely put, Cheers! canadian pharmacies that are legit
You actually said it very well! dangers of kratom