Lab 2 - Time and Time Again
David B. Levine
Computer Science Department
St. Bonaventure University
Copyright, 2004

Objective

            In this lab we will examine how different implementations of the same class behave when treated in a programming-by-contract world.  We will do so by implementing the same class in two different manners.

 


Instructions:

  1. Begin by downloading the file Time.java to your computer.  Start Eclipse and create a project named TimeGames.  Place the file Time.java into the project and then open it in the editor.  What are the methods in this class?  What are the instance variables?  What, if any, are the differences between today's class and the one described yesterday in lecture?  Explicitly record your answers to these questions.

  2. Create a new file named TimeTest.java.  When asked by Eclipse, include a main method in this class.  This main method should test each of the methods in the Time class.  For each method, be sure to test it somewhat thoroughly.  Performing only one test is not sufficient - as you learned with the 3Sort program last week! 
  3. Explain the basics of your testing strategy.  WARNING: I deliberately left at least one bug in the code.  (I'll probably claim that others were deliberate, too!)  Your explanation should include how you found it!

  4. When you are convinced that you have tested the class well, print out the TimeTest class.  Also print out the contents of a console window that shows a run of the program.

  5. We will now change the Time.java class.  Instead of storing minutes and seconds, it should now store only the total number of seconds (as was done in lecture yesterday.)  This means that you will need to rewrite most (or all!) of the methods to accommodate this change! 

  6. When you are sure that your new implementation works, run the TimeTest program again, recording the console output.

  7. Explain any differences (or lack thereof) between the output from the two different runs of the TimeTest main method.  Relate this to the discussions in lecture. 

  8. Print the (new) Time.java class.

Hand in:

        Hand in a cover page, the answers from Step 1, the explanation from Step 2, the listings from Step 3, the explanation from Step 6, and the printouts from Step 7.

 

Assignment Type (see Academic Practices and Policies Document):

Help Policy in Effect for This Assignment:  Group Project with Limited Collaboration

In particular, you may discuss the assignment and concepts related to the assignment with the following persons, in addition to an instructor in this course: any member of your group; any St. Bonaventure Computer Science instructor; and any student enrolled in CS 132. 

You may use the following materials produced by other students:  materials produced by members of your group.