CS 4773 Object Oriented Programming, Spring 1999
Assignment 2

Due Thursday, February 11


This assignment has 4 parts.
In this assignment you will write an applet to test the time resolution of the Java virtual machine and the speed of a particular Java system call.
Note that we are using Java 1.1 and you may not use any deprecated methods.
Turn in a copy of the source code for all parts of the assignment by the start of class on the due date.
Do not destroy the source code for any assignment you have done for this course until the course is over.
For each part that you get to work correctly you will put the class file and an html file under your public_html directory and put a link to execute the applet on your course web page.
The source code for your applets should not be public.


Part 1:
Make another copy of your applet from assignment 1 and call the new copy TimeTest1.java. Modify it as follows. Add a button to the applet called Start. Change the label on the text field to Number of Iterations. The messages which display the number should be updated when a new number is entered (a return is pushed) or the Start button is pushed.

Put a copy of the class file where it can be accessed from your course web page and put a link to it in your course web page.
The link should be labeled Assignment 2, Part 1 (TimeTest1).
Make sure you set the permissions so that anyone can access it from a browser.

Part 2:
Copy TimeTest1.java to TimeTest2.java and modify it as follows. The number to be entered should be an integer. The integer represents the number of iterations in a loop. If the value is n, then a push of the Start button causes n+1 calls to System.currentTimeMillis() to be put in consecutive entries in an array. No other calculations should occur in this loop. When the loop is done, create another array of size n which will contain the differences between consecutive values of your first array. The applet will then display various statistics about this second array of n differences. Instead of displaying one hundred times the number, display the following information on separate lines in the following order with the appropriate description.

All of this display should appear after the button is pushed. When a new number is entered, the information above should not appear. It should be possible to enter new numbers and push Start again to perform a new calculation. The last of these should be a floating point value. Handle averages of zero items in a graceful way. Since the display will take up several lines, the message containing your name may need to be moved. It should be the last line displayed.
Put a link labeled Assignment 2, Part 2 (TimeTest2) on your course web page.

Part 3:
Copy TimeTest2.java to TimeTest3.java and modify it as follows. Write a method for sorting an array of integers. Create a third array which just contains the non-zero differences from the second array. Use the count of the non-zero differences to allocate an array of the correct size. Sort this array and display the following additional information:

Put a link labeled Assignment 2, Part 3 (TimeTest3) on your course web page.

Note: You may use a simple order n-squared sort for this assignment.

Part 4:
Write a short report indicating which platforms you tested your applet under and the summary of what you learned about the time resolution of the System.currentTimeMillis() method under those platforms. Make a web page with this information, print it out and hand it in with your source code for the other three parts of the project. Put this report in your web-accessible directory and make a link to it on your course web page, but make the file readable only by you for now (permissions rw-------).