Lab 2: Progressions
Objectives. The objectives of this lab are:
- to provide practice using Java's inheritance and polymorphism
mechanisms to design a class.
Installing DrJava
DrJava is an easy-to-use open source integrated development
environment (IDE) for Java. An IDE includes an editor, compiler,
and run-time environment for Java within the same application.
Download and install DrJava by following these instructions. Once DrJava is
correctly installed, return to this page and proceed to complete
the lab exercise.
Part I: Progression 1
Source
Goodrich and Tamassia, p. 93, Problem C-2.2
Write a Java class that extends the Progression class
to produce a progression where each value is the absolute value
of the difference between the previous two values. You should include
a default constructor that starts with 2 and 200 as the first two
values and a parametric constructor that starts with a specified
pair of numbers as the first two values.
Suggestions
- You can use the static Math.abs()
method to calculate the absolute values.
- Create a separate directory under your cpsc215 directory
for this problem. Then change into that directory and download the
following source files into that directory:
- Before defining your own subclass of Progression,
compile and run Tester.java to show that it works correctly
for the ArithProgression class. To compile
all your source code, including Progression.java,
Tester.java, and the source file you create, you would simply
type.
javac Tester.java
To run your program, you would simply type:
java Tester.java
- To test your program, you will have to revise the
main() program in the Tester.java class.
Part II: Progression 2
Source
Goodrich and Tamassia, p. 93, Problem C-2.3
Write a Java class that extends the Progression class to
produce a progression where each value is the square root of the
previous value. (Note that you can no longer represent each value with
an integer.) You should include a default constructor that starts
with 65,536 as the first value and a parametric constructor that
starts with a specified (double) number as a first value.
You're done. Great work!