On this page:
Instructions
Problem 1: Visitors
8.5

Assignment 7: Visitors

Goals: To practice using the visitor patterns.

Instructions

As always, be very careful with your naming conventions. You should not use mutation on this problem.

Due Date: Monday, June 2nd at 9:00pm

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