Write a program to manage a set of points and their relationship to a "viewpoint" in 3D-space.
(See equation 1. N is the number of dimensions. The equation has been corrected from the original version. )
In this assignment you will build the following classes:
Point
which stores information needed for a point.Space
which stores a collection of points. You may
assume that there will never be more than 100 points in a Space.
However, feel free to use java.util.Vector
or
java.util.ArrayList
. A1Driver
which contains a main method that allows a user
to read in points and store them in a Space and interactively
perform a set of commands. You may assume that
all input to A1Driver
has the correct format.SpaceTester
, which contains a set of test
cases that demonstrate the correctness of
Space
. Be sure to provide a description of
each test case (as a comment). You can read more about testing
below.
A1Driver
will provide the user with a set of commands to
run. The main method of A1Driver
will prompt the user for
which command to run, and will prompt for any input required by the user.
The commands will be implemented by the method signatures given to you
in A1Driver.java
. You will fill in the method bodies, and complete
main, but you must not change anything that is given in
A1Driver.java
, since these are the methods that our testing
program will call.
The javadoc output for A1Driver is also available.
You will need to think carefully about how the functionality is
divided up between the different classes. Some, but not all of the
methods in A1Driver
will simply call the corresponding
method on the space object.
How easy would it be to change your program so that points had 4 dimensions? If you have written it carefully, you should only need to change methods and instance variables in the Point class.
Being able to order points in 3D space has lots of applications. The most obvious application is in graphics algorithms where we want to find out if an object or a point on a object is visible. The dimensions do not need to represent real 3-dimensional state. We might simply be trying to find a function that compares sets of variables. For example, a contest to guess the birth date, weight, and gender of a baby needs to compare the actual birth data, weight and gender to the guesses and determine which of the guesses is closest. (There are other more serious examples, of course.)
Method main
of SpaceTester
thoroughly tests the public interface of
Space
. SpaceTester
is entirely separate from A1Driver
. It manipulates
Space
s directly rather than through the
keyboard, and is purely for testing. Think of A1Driver
as
the program that users will run, and
SpaceTester
as the program that will
convince your boss that Space
is correct.
(Don't forget to test A1Driver
yourself, though, just to
make sure that Add, Get, and so on work as they should.)
Refer to the Software Testing guide included near the front of the 148/A58 Lecture Notes for more testing tips.
An example test case might create a Space
,
add a Point to it, and then retrieve the Point at location 0 --and it
should be the same item you added.
Here is pseudo-code for that example test case, complete with comment:
// Test adding and retrieving one element to a Space. add "E" to the Space if (the item at location 0 in the Space is not "E") { print "Simple add/get failed." }
Note that using this style of testing, there is only output if an error occurs. It is common practice to write test cases at the same time as (or even before!) you write a class, and then run the testing program, fixing each error as it occurs.
Point.java
, Space.java
,
A1Driver.java
, SpaceTester.java
and any
other classes you wrote.