Stopwatch Project Create a class that represents a stop watch which includes the
ID: 3906912 • Letter: S
Question
Stopwatch Project Create a class that represents a stop watch which includes the following: Private data fields startClock and endClock with get methods for each Ano-argument constructor which initializes startClock with the current time A method named start timer) which resets the startClock to the current time * . .A method named stop timer) which sets the endClock to the current time A method called getElapsed) which returns the elapsed time in milliseconds You are required to test your program in measuring the execution time of sorting 10000 numbers using bubble sort. Hint: You can use System.currentTimeMillis. For example, long startClock Systen.currentTinem ? ts(); -Explanation / Answer
public class StopWatch { private long startClock, endClock; public StopWatch() { startClock = System.currentTimeMillis(); } public long getStartClock() { return startClock; } public long getEndClock() { return endClock; } public void start_timer() { startClock = System.currentTimeMillis(); } public void stop_timer() { endClock = System.currentTimeMillis(); } public long getElapsed() { return endClock - startClock; } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.