CS 211, 004/006
Lab Exercise-3
due Thursday, September 20th at noon


The objective of this lab is to be able to build simple classes, including designing the needed data structure and implementing the requested behaviors; also to be able to effectively use Java methods for processing input (Scanner).

Overview:

  1. Write two Java classes which implement the requested functionality. The first one will implement a stopwatch, while the second one will implement an arithmetic accumulator.
  2. Download and use a tester module to ensure that your programs are correct. The programs can also be tested using Dr Java's interactive window.
  3. Prepare the assignment for submission and submit it
This is a lab exercise on which collaboration (including discussing the solution on Piazza or searching online sources) is explicitly permitted. It is still in your interest to understand and prepare your final submission yourself.

Stopwatch Task:

(4pts) First, write a class named Stopwatch. This class should keep track of the time from the start (at a millisecond resolution) and be able to report the time. You will probably want to use a call from System which gives you information about the time in milliseconds. You may not use any import statements. Any data elements should be declared private, although this will not be graded. The class should implement the following methods:

All method signatures should match the ones shown exactly.

Accumulator Task:

(5pts) Now, write a class named Accumulator. This will keep track of a (double) number which represents a running total. New values can be added to this total, and the total can be reported. Additionally, there will be methods for reading data from the input and feeding it to the accumulator. The only import statement you may use in this implementation is the Scanner class. Any data elements should be declared private, although this will not be graded. The class should implement the following methods:

Testing:

Download the following (if you don't already have it):

This is a unit tester which is what we will use to test to see if your classes are working correctly.

When you think your classes are ready (you can try them even without the tester), do the following from the command prompt to run the tests.
On Windows:

javac -cp .;junit-cs211.jar *.java
java -cp .;junit-cs211.jar E3tester
On Mac or Linux:
javac -cp .:junit-cs211.jar *.java
java -cp .:junit-cs211.jar E3tester
In Dr Java:

Submission:

Submission instructions are as follows.

  1. Let xxx be your lab section number (one of 213-220), and let yyyyyyyy be your GMU userid. Create the directory xxx_yyyyyyyy_E3/
  2. Place all of the .java files that you've created into the directory.
  3. Create the file ID.txt in the format shown below, containing your name, userid, G#, lecture section and lab section, and add it to the directory. Your directory should contain three files total.

    Full Name: Donald Knuth
    userID: dknuth
    G#: 00123456
    Lecture section: 004
    Lab section: 213

  4. compress the folder and its contents into a .zip file, and upload the file to Blackboard.