Apply Exercise P16.22 to compute the average value of the elements in a binary search tree filled with Integer objects. That is, supply an object of an appropriate class that implements the Visitor interface.

Complete the following files:

AverageCalculatorVisitor.java

BinarySearchTree.java

Use the following file:

VisitorTester.java

public class VisitorTester
{
   public static void main(String args[])
   {
      BinarySearchTree t = new BinarySearchTree();
      t.add(1);
      t.add(5);
      t.add(10);
      t.add(8);
      t.add(7);
      t.add(3);
      t.add(6);
      t.add(2);
      t.add(9);
      t.add(5);
      t.add(4);
      
      AverageCalculatorVisitor v = new AverageCalculatorVisitor();
      t.inOrder(v);
      System.out.println("Average: " + v.getAverage());
      System.out.println("Expected: 5.5");
   }
}