Question: In Class Programming Assignment 8: StopWatch Class Problem Description: *9.6 (Stopwatch) Design a class named StopWatch The class contains: Private data fields startTime and endTime

In Class Programming Assignment 8: StopWatch Class

Problem Description:

*9.6 (Stopwatch)

Design a class named StopWatch

The class contains:

Private data fields startTime and endTime with getter methods.

A no-Arg constructor that initializes startTime with the current time.

A method named start() that resets the startTime to the current time.

A method named stop() that sets the endTime to the current time.

A method named getElapsedTime() that returns the elapsed t

ime for the stopwatch in

milliseconds

In Class Programming Assignment 8: StopWatch Class Problem Description: *9.6 (Stopwatch) Design

This is the source code I have so far I need help finishing it to get it to display start and end time approprietly.

Please provide information on what does what throughout the source code during each line.

package teststartwatch;

/**

*

* @author Home

*/

public class TestStartWatch {

private long startTime;

private long endTime;

// No-arg, initializes startTime

TestStartWatch() {

startTime = System.currentTimeMillis();

}

void start() {

startTime = System.currentTimeMillis();

}

void stop() {

endTime = System.currentTimeMillis();

}

long getElapsedTime() {

return endTime - startTime;

}

}

package teststartwatch;

/**

*

* @author Home

*/

import java.util.Random;

public class Main {

public static void main(String[] args) {

int[] list = new int[100000];

Random random = new Random();

// Fill list with random 100,000 integers

for(int i = 0; i

list[i] = random.nextInt(100);

}

// Start timer and sort

TestStartWatch stopwatch = new TestStartWatch();

selectionSort(list);

stopwatch.stop();

System.out.println((1000 / stopwatch.getElapsedTime()) + "s");

}

public static void selectionSort(int[] x) {

for(int i = 0; i

int minIndex = i;

for(int j = i + 1; j

if(x[minIndex] > x[j]) {

minIndex = j;

}

}

if(minIndex != i) {

int temp = x[i];

x[i] = x[minIndex];

x[minIndex] = temp;

}

}

}

}

Sample Output: Output StopWatch (run) X Dreaa any key and than anser tatop the stop watch and display the elapsed time in malil.aconda.3 Start Time: 150766132665 End Time: 1507661329223 BUILD SUCCESSFUL (total tine: 2 aeconda)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!