Question: The System class contains a static method currentTimeMillis. Explore the Java API (https://docs.oracle.com/iavase/8/docs/api/) for the specification of the method. Write a short test program to


The System class contains a static method currentTimeMillis. Explore the Java API (https://docs.oracle.com/iavase/8/docs/api/) for the specification of the method. Write a short test program to ensure you are using it properly. What is the return type? 3. Using this information create a StopWatch class. This class will contain the following members Private data fields to represent a start time and end time A default (no-arg) constructor that initializes the start time with the current time (using currentTimeMillis). A method named start) that resets the start time to the current time .A method named stop that sets the end time to the current time A method named getElapsedTime ( that returns the elapsed time for the stopwatch in seconds (1 sec = 1000 milliseconds). To demonstrate your StopWatch class, determine how long it takes to print all prime numbers between 2 and 1 million 4. Add a private class (static) variable to the StopWatch class that counts the number of StopWatch objects that have been created during a run of the program. Add an appropriate getter for this value. Why not add a setter too? Use this code to test your modified stopWatch class: System.out.println (StopWatch.getNumobjects()) StopWatch swl -new stopWatch ); System.out.println (StopWatch.getNumObjects()); StopWatch sw2new stopWatch System.out.println (StopWatch.getNumobjectsO) // you can also access through an object System.out.println (sw1.getNumobjects))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
