Department of Computer Science and Engineering CSE 130
University of California at San Diego Fall 1999

Team Project 3

DUE FRIDAY NOVEMBER 19, 1999, BEFORE 6 PM.

This assignment is intended to demonstrate differences and similarities between the C++ and Java languages.  For this project you will use abstract data types (ADTs) and exception-handling features.

Java and C++ are both object-oriented programming languages, so they provide a generalization of ADTs in the form of classes and objects.  In order to show that you understand the ADT concept, you should not use all the object-oriented features of these languages.  Instead, you should only use a subset that approximates the concept of ADT as described in class, as closely as possible.  In your report, you should discuss to what extent ADTs (as opposed to general classes and objects) can be programmed in Java and in C++.

You should use the Java facilities for handling exceptions and for creating pointer-based data structures without explicit pointers.  Exceptions are supposed to make defensive programming easier.  Java provides exceptions using the primitives try and catch. The lack of explicit pointers is supposed to reduce memory management errors and make automatic garbage collection easier.  In your report, you should discuss how you use each of these Java features.

You should not use any C++ features for exception-handling.  Based on your experience, in your report, you should discuss how helpful (or not) it is for a programming language to provide special features for exception-handling.

The assignment is to implement in C++ and Java an abstract data type for the use of Comrade Spock.  In a twisted universe Spock is the navigator of the starship Gosplan in the USSSS (Union of Soviet Socialist Solar Systems) fleet.  Comrade Spock needs a type of values which are maps of the universe.  The universe is a four-dimensional Euclidean hyperspace where the fourth dimension is time.  The unit of measure in all four dimensions is the parsec, and the universe is bounded between -1000.0 and +1000.0 parsecs in each dimension.

The ADT you implement is a type where each value of the type represents an entire universe.  The ADT must support the following operations:

You will use this structure to run a simulation of the future positions of all ships assuming velocity does not change unless specified below.  Use Euclidean geometry to calculate the distance d between objects, i.e. the familiar equation d2 = x2 + y2 + z2 + t2.  The following special conditions apply: Your abstract data type should be pure, i.e. an operation should return a "new" universe rather than make changes to an "old" universe. The ADT should allow for an arbitrary number of rebels and wormholes.  In the movement simulation, the time step for each ship will be different, depending on its time-velocity relative to the Gosplan.  You will need to scale the change in each direction by the ratio between the time-velocity of the ship and the time-velocity of the Gosplan.  As an example, say the Gosplan is at location <a,b,c,d> with velocity <1,1,1,1> and a rebel ship is at <e,f,g,h> and velocity <2,3,4,2>.  At the next second in the simulation, the Gosplan ends up at <a+1,b+1,c+1,d+1> but the rebel ship ends up at <e+4,f+6,g+8,h+2> because it is moving twice as fast (tv=2) as the Gosplan in time.

If the Gosplan is caught in a loop of wormholes, or if other dangerous conditions occur, appropriate exceptions should be raised.  But think about the interaction between the ideas of exception-raising and information-hiding.  Test cases will be published on a separate web page.
 

WHAT TO SUBMIT BY COMPUTER

You should create two tar files: java.tar and cpp.tar, containing the programs. The file java.tar will contain all your source files for the java program plus the compiled files. The file that contains the main will be called spock.class. The cpp.tar will contain all your source files and a Makefile that generates an executable file called spock. Use the gcc compiler for your C++ program.

To turn in your work, you will use a script called bundle. Simply cd to the directory containing all two source files and type the Unix command bundleP3. The bundle script knows which files to look for and submit. Remember to check the class web page (http://www-cse.ucsd.edu/classes/fa99/cse130/) for any changes to these directions.
 

WHAT TO SUBMIT ON PAPER

You should describe all your work in a well-written report of length at most ten pages.  Follow the same requirements as for the previous assignments with regard to the paper. References that you may use are web pages and books. One recommended web page for information's on the Java language is http://java.sun.com/docs/books/tutorial/index.html.

For your report, you should consider and address the following questions, in addition to other issues which arise during the course of your assignment:

As an appendix to your report, you should submit a printout of your software, with comments and documentation of professional quality. This documentation should be sufficient for another software engineer to maintain each program. Remember that good documentation is necessary but not sufficient. You should attach transcripts of test runs that show both your programs working correctly on the test sequences that will be published.

Be sure to follow all the rules and guidelines explained in the CSE 130 course description.  Complete academic honesty is required.