第九章第六题(秒表)(Stopwatch)
-
*9.6(秒表)设计一个名为StopWatch的类,该类包含:
- 具有设置方法的私有数据与startTime和endTime。
- 一个无参构造方法,使用当前时间来初始化startTime。
- 一个名为start()的方法,将startTime重设为当前时间。
- 一个名为stop()的方法,将endTime设置为当前时间。
- 一个名为getElapsedTime()的方法,返回以毫秒为单位的秒表记录的流逝时间。
画出该类的YML图并实现这个类。编写一个测试程序,用于测量使用选择排序对100000个数字进行排序的执行时间。
*9.6(Stopwatch)Design a class named stopwatch, which contains:- Private data with setting method and starttime and Endtime.
- A nonparametric constructor that initializes starttime with the current time.
- A method called start() resets starttime to the current time.
- A method called stop() sets Endtime to the current time.
- A method called getelapsedtime() returns the elapsed time recorded by the stopwatch in milliseconds.
Draw the YML diagram of the class and implement the class. Write a test program to measure the execution time of sorting 100000 numbers using selective sorting.
-
参考代码:
package chapter09;
public class Code_06 {
public static void main(String[] args){
StopWatch time = new StopWatch()