Java Assignment Java Assignment Due November 15 This assignment has two parts, to be submitted to the TA, raghavan at cs.nyu.edu, as two separate Java files. Part I In the file prog.java is a simple definition of a Vehicle class. Create two other classes for particular vehicle types (trucks, submarines, whatever you like) that extend the Vehicle class to include fields and methods appropriate to the particular type of vehicle. In the new classes you define, override the set_speed() method so that an exception is raised if the speed to set to a value above a threshold of your choosing. You should do this by creating a new exception class for reporting that a speed limit violation has occurred. The versions of set_speed() in the new vehicle classes that you created should throw this kind of exception. Write a method, not within the Vehicle class, that takes any two vehicle objects and returns the one that is moving faster. Write a method, also not within the Vehicle class, that takes any two objects (not necessarily vehicles) that provide a method with the signature:
int get_speed()
and prints out the speed of each object. Modify the main() method provided in the file to exercise all of the code specified above. Keep it in the prog class. Be sure to have main() try to set the speed of one of the vehicles past the speed limit, and then handle the exception that is raised. Part 2 In the file Tree.java, you will find class definitions for the nodes making up a binary search tree. These classes, InnerNode and Leaf, are derived from the abstract parent class Node. You will also find a main() method (in a different class) that constructs a binary tree. Implement a visitor pattern (like in the Test7.java file discussed in class) by adding the accept method to each Node class, defining the appropriate visitor interface, and creating a visitor class, PrintVisitor that prints out the nodes of the tree (using the usual pre-order traversal). Replace the current code in Tree.java for printing out a tree by PrintVisitor. Implement a binary search visitor, SearchVisitor, which can be used to determine if a particular value appears as a label in the tree. Then, modify the main() method to run some binary searches on the tree. (Note: If you are not familar with binary search trees, click here). Create another visitor class, InsertVisitor, which supports inserting a new node in the appropriate place in the binary search tree. Modify main() to insert new nodes in the tree using InsertVisitor. Important: In order to be able to define a single visitor interface that will work for printing, performing binary search, and for inserting new nodes in the tree, you will probably need to use generics (i.e. define the Visitor interface and the accept() methods as generics).