CSci 581-01: Special Topics in Computer Science
Object-Oriented Design & Programming
Spring Semester 1999

Assignment #3
Due Midnight, Thursday, 29 April


Assignment Option Overview

This assignment has the following options. Each individual must select one of these options by Tuesday, 13 April, and stay with that choice.

  1. In groups, complete the design and implementation of the CRC Card Tools as described in Assignment #2.

  2. As an individual, complete the expression-evaluation assignment described below.

For option 1, the groups may consist of two or more members of the same groups as for Assignment #2. You may not form groups whose members were in different groups for assignment #2.



Option 1: CRC Card Tool Set



Option 2: Simple Expression Evaluator

This assignment requires you (as an individual) to design, implement, test, and document an object-oriented Java program to input, evaluate, and output arithmetic expressions. The program should handle the following types of prefix-form expressions:

An example of this type of expression is:

    sum( 2, prod( 3, 4, -2 ), diff( 3, quot( 8, 2 )), 10 )

Tasks

  1. Design and implement an abstract base class Expr with instance methods eval and toString:

    eval
    evaluates the expression (i.e., the Expr object, not the String given as input) and returns the resulting value as a double.
    toString
    converts the expression (i.e., the Expr object) to a String in prefix form (as shown above) and returns it.

  2. Design and implement subclasses Numeric, Sum, Product, Difference, and Quotient of Expr.

    The subclasses should override eval and toString as appropriate. Your design should take advantage of polymorphism.

    A Numeric object should store the number as a double internally. The other subclasses should use appropriate collections of Expr objects internally.

  3. Design and implement a class (i.e., static) method parse of Expr that takes a String and returns the equivalent Expr object. Hint: You may want to implement this method as a simple recursive descent recognizer for the expression language. You may also find the class java.util.StringTokenizer or the class java.io.StreamTokenizer useful.

    Note: The input string to parse() should not be stored in the instances of the Expr classes.

  4. Design and implement an instance method toInfix that converts the expression to standard algebraic infix notation, such as
        2 + 3*4*(-2) + (3-8/2) + 10
    
    The challenge is not to print unnecessary pairs of parentheses.

  5. Test your program appropriately.

  6. Document your program for use with the Javadoc utility. Use of preconditions, postconditions, and invariants is also recommended.

  7. When this assignment is complete, submit a paper listing of your program source code and testing input/output.

  8. Also submit your program source code using EASE, the Electronic Assignment Submission Environment, at URL http://www.cs.olemiss.edu/submit/.


UP to CSci 581 Assignments page?


Copyright © 1999, H. Conrad Cunningham
Last modified: Thu Apr 29 15:03:58 CDT