Hello Java (June 29)
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
- A single class:
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.
- Writing a method
As the documentation describes, the
tests whether the interval between two given endpoints contains any real
numbers. Write the body of this method.
- Testing your implementation
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
- A dependent class:
- Writing the class
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.
- Writing the tests
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.
- Adding some new methods
- Scaling an endpoint
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
- Scaling an interval
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.
- More tests!
Now write some more tests in the two classes
IntervalTest to test your new methods, and run them to make
sure they all pass.
- Tutorial feedback
Please take a minute to briefly answer the following questions so we can
make sure these tutorials stay useful and enjoyable:
- What do you like about the tutorials themselves?
- What don't you like about the tutorials (what could be improved)?
- Is the pace too slow, too fast, or just right?
- Is the material covered relevant, or should we be focusing on some other
- Any comments on the (in)effectiveness of your tutorial instructor?
- Any additional comments about anything relating to CS136?
Thanks for your (anonymous) feedback, and know that we will take your
comments into consideration.
Last modified on
Wednesday, 09 January 2019, at 14:31 hours.