On this page:
Instructions
Problem 1: Visitors
Problem 2: The Registrar’s Office
7.1 Data constraints
7.2 Methods and examples to design
7.7

Assignment 7: Visitors and Mutation

Goals: To practice using the visitor pattern.

Instructions

As always, be very careful with your naming conventions.

The submissions will be organized as follows:

Problem 1: Visitors

In a new file Visitors.java, implement the following class diagram:
      +-------------------+
      | IArith            |
      +-------------------+
      +-------------------+
          /_\      /_\
           |        |----------------------------------------------------------------
           |        |                                                               |
+-------------+  +------------------------------+           +------------------------------------------+
| Const       |  | UnaryFormula                 |           |              BinaryFormula               |
+-------------+  +------------------------------+           +------------------------------------------+
| double num  |  | Function<Double,Double> func |           | BiFunction <Double, Double, Double> func |
+-------------+  | String name                  |           | String name                              |
                 | IArith child                 |           | IArith left                              |
                 +------------------------------+           | IArith right                             |
                                                            +------------------------------------------+

Specifically, the above represents an arithmetic expression. The Function and BiFunction in UnaryFormula and BinaryFormula respectively denote the arithmetic operation to be applied to their respective operands (child and left,right).

You must support 4 binary formulas (named "plus", "minus", "mul" and "div" representing addition, subtraction, multiplication and division respectively), and 2 unary formulas (named "neg" and "sqr" representing negation and squaring respectively).

Problem 2: The Registrar’s Office

The registrar’s office maintains a great deal of information about classes, instructors, and students. Your task in this problem is to model that data, and implement a few methods on it. We deliberately do not give you the class diagram for this problem: from the description below, you should properly design whatever classes you think are relevant. Please use generic lists (i.e. IList<T>) for this problem.

7.1 Data constraints
7.2 Methods and examples to design