Today's tutorial is a basic overview of how to use Dr. Java to write simple classes with some interaction. We will also cover the basic standards and conventions for documentation, formatting, and testing. The material for this tutorial is related to Lecture Module 8 (see handouts).
In the skeleton code for today's tutorial, you will find the
Endpoint class, which represents a single endpoint for an interval
on the real number line. Already written are the three private fields
boolean infinite, and
boolean closed, as well as two constructors. Read over the
documentation in the class so that you understand what these fields are for
and how the constructors are used.
As the documentation describes, the
tests whether the interval between two given endpoints contains any real
numbers. Write the body of this method.
Now open the class
EndpointTest (also included in the skeleton
code). First inspect the tests and make sure you understand their purpose, then
main method in the
EndpointTest class to test your implementation of
Create a new class (and corresponding file) called
to represent a single interval on the real number line. You should have two
private fields for the left and right
Endpoints, and a single
constructor which takes two endpoints as arguments. You should also create
a public method,
contains, which takes one
value and tests whether that point is contained in the interval or not.
In the same style as the
EndpointTest class, write a class
IntervalTest which contains some tests for your implementation
Interval class. Then run your tests in Dr. Java to make
sure they pass.
Add a new method to the
Endpoint class called
which takes one
double argument, produces no value, and mutates
Endpoint so that the location is multiplied by the given
scale method you just wrote in
write an identical method in the
Interval class which modifies the
corresponding interval in the same way. Note that you have to be careful when
the given magnitude is a negative number.
Now write some more tests in the two classes
IntervalTest to test your new methods, and run them to make
sure they all pass.
Please take a minute to briefly answer the following questions so we can make sure these tutorials stay useful and enjoyable:
Thanks for your (anonymous) feedback, and know that we will take your comments into consideration.
Last modified on Friday, 19 August 2011, at 18:05 hours.