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:
public Stopwatch()
the constructor will
initialize and start the stopwatch.public void reset()
this call will
restart the stopwatch.public double check()
this call
will print the elapsed time (in seconds) on the stopwatch since it was started (or the last time it was restarted). Use decimals to
represent fractional amounts.public String toString()
returns the same
value as check()
, except formatted as a
String
.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:
public Accumulator()
this constructor will
initialize the accumulator with a zero total.public void reset()
this call will
reset the running total to zero.public void add(double val)
adds
val
to the running total.public double getTotal()
retrieves the
current total.public void readNumbers(Scanner s)
reads numbers
from the (pre-initialized) Scanner
object and adds the to the accumulator. It should read the numbers as floating point values, skipping any tokens which are not numbers, and continuing until there are no more tokens in the input.public void readNumbers(String str)
same
as above, except that the input should be read from the
given String
. Hint: if you read the documentation for Scanner
, it should be helpful here as well.
public String toString()
returns the
current total, formatted as a String
.
javac -cp .;junit-cs211.jar *.java
java -cp .;junit-cs211.jar E3tester
javac -cp .:junit-cs211.jar *.java
java -cp .:junit-cs211.jar E3tester
E3tester.java
, and click the Test button.
Submission instructions are as follows.
xxx_yyyyyyyy_E3/
.java
files that you've
created into the directory.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