Computer Science 3675
Fall 2002
Programming assignment 6

Due: Wednesday, November 13.

This assignment has you redo the derivative computing program in Java.

Your first derivative program uses a type with several constructors to represent expressions. Java is an object-oriented programming language, and object-oriented programming has a different way of managing types with several flavors. You create a class Expression that stands for an arbitrary kind of expression, and a subclass of Expression for each kind of expression.

This has the advantage that new kinds of expressions can be added just by adding new subclasses. It is not necessary to modify any existing code; you just add new code. Removing a kind of expression is just a matter of removing a subclass. If you imagine providing expressions and derivative computations in a library (which most programmers are not allowed to modify) you can see how useful this approach is. Programmers can add their own kinds of expressions without the need to modify the library.

A starting point is provided for you. Extend this to handle the subtraction, multiplication and constant powers, as you did for assignment 5. A tester is also available. Try compiling and running the starting point files before trying to modify them.

Running Java programs

There are many implementations of Java available. I will only describe one, and will only describe the most basic aspects of that one. On the Unix machines in the lab, the Java compiler is called javac. Compile Derivatives.java using command

 javac Derivatives.java
This creates files Expression.class, etc., one for each class that is defined. Compile TestDeriv.java similarly. To run a Java program, use the Java interpreter. Command
 java TestDeriv
runs TestDeriv.class, by running the main program that is contained there.

Turning in your solution

Hand in your program using the handin utility, as assignment 6. Turn in both your tester and your file containing the expression classes. Please continue to call them Derivatives.java and TestDeriv.java to make testing easy for me.