Assignment 1: Distance in Space

Purpose

Write a program to manage a set of points and their relationship to a "viewpoint" in 3D-space.

Objectives

Overview

A point in 3D-space is defined by its coordinates along each of the dimensions. The distance between two points in 3D-space is the square root of the sum of the squares of the absolute differences between the coordinates in each dimension

(See equation 1. N is the number of dimensions. The equation has been corrected from the original version. )

equation

In this assignment you will build the following classes:

User commands

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.

Notes

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.)

Testing

Method main of SpaceTester thoroughly tests the public interface of Space. SpaceTester is entirely separate from A1Driver. It manipulates Spaces 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.

Marking

What to submit electronically. (No paper submission.)


Last modified: Fri Sep 27 14:34:17 EDT 2002