import com.seanhandley.projects.BinaryTree.*;
/**
*
* Client test code for the generic binary tree object.
*
* @author Sean Handley, 320097@swan.ac.uk
* @version May 2007
*/
public class Client {
private BinaryTree<Car> carTree1;
private BinaryTree<Car> carTree2;
private BinaryTree<Plane> planeTree;
private CarStrategy1 cs1;
private CarStrategy2 cs2;
private PlaneStrategy ps;
/**
* Constructor.
*/
public Client()
{
cs1 = new CarStrategy1();
cs2 = new CarStrategy2();
ps = new PlaneStrategy();
carTree1 = new BinaryTree<Car>(cs1);
carTree2 = new BinaryTree<Car>(cs2);
planeTree = new BinaryTree<Plane>(ps);
/*
* carTree2 = new BinaryTree<Plane>(cs2);
*
* gives two errors:
*
* The constructor BinaryTree<Plane>(CarStrategy2) is undefined
*
* Type mismatch: cannot convert from BinaryTree<Plane> to BinaryTree<Car>
*/
/*
* carTree2 = new BinaryTree<Car>(ps);
*
* gives the following error:
*
* The constructor BinaryTree<Car>(PlaneStrategy) is undefined
*/
}
/*
* Run test code.
*/
private void test()
{
//car code 1
System.out.println("Tree is empty? " + carTree1.empty());
carTree1.add(new Car(5000,"Ford","ABC123"));
carTree1.add(new Car(4000,"Honda","CDE456"));
carTree1.add(new Car(8000,"Skoda","EFG789"));
carTree1.add(new Car(2000,"Porsche","HIJ123"));
carTree1.add(new Car(1000,"Volkswagen","KLM456"));
System.out.println(carTree1.toString());
System.out.println("Tree is empty? " + carTree1.empty());
System.out.println("Nodes in tree: " + carTree1.size());
System.out.println("Visitor says: " + carTree1.visit(new CarVisitor1()));
/*
* System.out.println("Visitor says: " + carTree1.visit(new PlaneVisitor1()));
*
* gives the following error:
* The method visit(IVisitor<Car,R>) in the type BinaryTree<Car> is
* not applicable for the arguments (PlaneVisitor1)
*/
//car code 2
System.out.println("Tree is empty? " + carTree2.empty());
carTree2.add(new Car(5000,"Ford","ABC223"));
carTree2.add(new Car(4000,"Honda","CDE456"));
carTree2.add(new Car(8000,"Skoda","EFG789"));
carTree2.add(new Car(2000,"Porsche","HIJ223"));
carTree2.add(new Car(1000,"Volkswagen","KLM456"));
System.out.println(carTree2.toString());
System.out.println("Tree is empty? " + carTree2.empty());
System.out.println("Nodes in tree: " + carTree2.size());
System.out.println("Visitor says: " + carTree2.visit(new CarVisitor1()));
//plane code
System.out.println("Tree is empty? " + planeTree.empty());
planeTree.add(new Plane(30,"Concord","ABC123"));
planeTree.add(new Plane(40,"Boeing","CDE456"));
planeTree.add(new Plane(80,"Harrier","EFG789"));
planeTree.add(new Plane(20,"MIG","HIJ123"));
planeTree.add(new Plane(10,"Wright Bros.","KLM456"));
System.out.println(planeTree.toString());
System.out.println("Tree is empty? " + planeTree.empty());
System.out.println("Nodes in tree: " + planeTree.size());
System.out.println("Visitor says: " + planeTree.visit(new PlaneVisitor1()));
}
/**
* Main method.
*
* @param args
*/
public static void main(String args[])
{
Client c = new Client();
c.test();
}
}