CS 4773 Object Oriented Programming, Spring 1998
Assignment 3

Due Thursday, February 12, 1998 at noon


Create an applet for testing how accurate the sleep method is in Java. Put the resulting applet on the web and put a link to it on your course web page.

This applet will be similar to the one from Assignment 2, Part 2, with the following differences.

There will be two text fields for entering the number of iterations, n, and the sleep time, s, in milliseconds. These should be labeled appropriately. When the Start button is pushed an array of n+1 longs will be created. The time will be stored in the first entry of the array (using System.currentTimeMillis) followed by a loop of n iterations. In each iteration, sleep for s milliseconds and store the time in the next entry of the array. When the loop is done you can start the analysis of the data.

Note that the loop must be done in a separate thread, as the applet itself is not allowed to sleep. We are interested in how the actual time slept as measuered by the difference in consecutive entries of the array compares to the requested sleep time. Calculate n values representing the difference between the actual time slept and the requested sleep time (sleep error). Note that this sleep error may be either positive (slept too long) or negative (did not sleep long enough). Display as many of the following statistics as you can:

The total error is the sum of all of the sleep errors.
The total absolute error is the sum of the absolute values of the sleep errors.
The number of positive errors should not include the zero errors.
The most common error may be zero.
The frequency of an error is the number of times that error occurred.
If you list all errors with frequency, the list should be ordered by frequency with the most frequent one first. You might want to use a TextArea (which is scrollable) for this while leaving the rest of the information in fixed positions.

You may lay out the applet using any method you wish.

Your full name should appear somewhere in the applet window.

See if you can have the word "Calculating" appear on the applet screen during the calculation. You might also want to display an indication of how far along the calculation is, but this should not affect the collection of the data.

Try out your program with various values of the sleep time and make several runs on one platform. Write a brief report of your results (at most one page, possibly with a table). Make sure you indicate exactly what hardware (e.g. Sparc 5 at 110 MHz, Pentium Pro at 200 MHz, etc.), operating system (Solaris 2.4, Windows95, etc.) and Java virtual machine (JDK 1.1.5, Netscape 4.01, etc.). If you can do this on a system other than one in our lab you should do so. This way we will get information about a variety of platforms.

If you wish, you can compare the results of several platforms. If you are running two operating systems on the same hardware this would be a good comparison.

Hand in a hard copy of your source code and your writeup.