Due: Wednesday 4/17 10:00am

Submission name: w20_evaluate

For this, you will need the ExpressionTreeNode and ExpressionTree classes, which you can get here: https://github.com/nextcs-dw/dwsource/tree/main/Expression

Reminder: Test Thursday 4/18

Expression Tree Nodes:

Modify the class so that when an operation node is displayed, it will show the operation and the value directly underneath the operation. Note: processing’s text() function will respect the \n character. toString() should not include extra newlines, since that would make traversals less useful.

Expression Tree:

  • Modify inOrder() so that it include () where appropriate.
  • Create a new method (and wrapper): float evaluate(ExpressionTreeNode current)
    • If current is an operation node, it should evaluate the operation using the left and right subtrees, and set current.value to that result.
    • It should always return current.value

Driver:

Call showStats() in draw(). Modify showStats() so that it evaluates the tree and puts the answer on the left side of the window.

a20-tree