/* AVL TREE AUTO QUIZ. Running this program will send a tree to a server which will check that it has the expected properties. This program will construct a tree with the following code (assuming 'ExtBst' is your class for AVL trees): Bst2020 tree = new ExtBst(); // if ExtBst is your AVL class for(int i=0;i<=800;i+=2) {tree.add(i);} for(int i=800;i>0;i-=8) { tree.remove(i); } for(int i=1;i<800;i+=2) { tree.add(i); } It will then send the tree through a network socket to the professor's server, which will then check the following properties: 1. whether or not the tree you sent is actually a binary search tree 2. whether your tree has the expected size 3. whether your tree has the expected height (depth) 4. whether your tree has expected values in the right locations You will get as response from the server a code and the corresponding message, for example: Response from server: code 3, tree does not have expected height This code means that you PASSED tests 1 and 2, but failed at test 3. This may or may not mean you've passed test 4. Similarly, if you get Response from server: code 2, tree does not have expected size This means your tree passed test 1 (is a binary search tree) but not test2, and the other tests haven't been made yet, so you need to figure out how debug your code for test 2 first. For the size test, make sure you add 'count++' to the code for insert in the extnil class. If you've passed all tests you will get: Response from server: code 5, tree validated, congrats You may also get the following: Response from server: code 0, tree rejected for unspecified reasons This means the server couldn't understand the tree or other information you've sent. Additionally if some error occurred when your tree is being constructed (during calls to .add and .remove), you will get a error message and no communication to the sever will be made. ======= BEFORE YOU RUN THIS PROGRAM, YOU MUST: ======= 1. Download the new version of Bst2020.java from cs.hofstra.edu/~cscccl/csc17/Bst2020.java Make sure it's new. You may want to save a copy of the original first. 2. Your program's class names must follow the outline I gave in lab 9a: It must have an outer class called ExtBst and inner classes called extnil and extvertex. It should not be hard to make these changes (but save copies of originals). Then ... a. Change the outer class heading to: public class ExtBst&java.io.Serializable> extends Bst2020 b. Add the following lines of code to the outer (ExtBst) class as well as each inner class, so that it will look like this in outline: public class ExtBst&java.io.Serializable> extends Bst2020 { public static final long serialVersionUID = 17171717L; class extnil extends nil { public static final long serialVersionUID = 171717170L; // 0L at end public Tree insert(T x) { count++; return new extvertex(x,this,this); } //... rest of your code } class extvertex extends vertex { public static final long serialVersionUID = 171717171L; // 1L at end //.. rest of your code } // .. rest of your code } The numbers, including 'L' at the end, MUST BE EXACT: Then recompile all classes together with this program, takequiz.java. The program should also work with the more advanced version of lab9, as long as your class names are as expected with the serialVersionUIDs above. AFTER YOU CHECKED THAT YOU DID THE ABOVE, take the quiz by running java takequiz "Your Name" 702123456 Replace the command-line arguments with your real name in quotes and with your real Hofstra ID number. You must enter the correct name and ID for results to be recorded. You may run the quiz as many times as you want until Friday 5/1. */ import java.io.*; import java.net.*; public class takequiz implements Serializable { public String name; // your name (last name suffice) public int id; // your Hofstra 70.. ID number public byte n; // response number to be filled out by server static String[] interp={"tree rejected for unspecified reasons", /*0*/ "tree is not a binary search tree", /*1*/ "tree does not have expected size", /*2*/ "tree does not have expected height", /*3*/ "tree does not have expected values", /*4*/ "tree validated, congrats"}; //5, how to interpret n public takequiz(String n, int i) { name=n; id=i; } static int SRVPORT = 17001; static String SRVADDR = "96.57.41.74"; // send to tcp server listening at ipaddr:BSTPORT static void takethequiz(String NAME, int ID) // { takequiz qr = new takequiz(NAME,ID); Bst2020 tree=null; try { tree = new ExtBst(); // your class must be called ExtBst for(int i=0;i<=800;i+=2) {tree.add(i);} for(int i=800;i>0;i-=8) { tree.remove(i); } for(int i=1;i<800;i+=2) { tree.add(i); } } catch (Exception e) { System.out.println("Error in your tree code, no communication attempted"); } try { // open socket to quiz server: Socket sout = new Socket(SRVADDR,SRVPORT); sout.setSoTimeout(3000); ObjectOutputStream bout = new ObjectOutputStream(sout.getOutputStream()); ObjectInputStream bin = new ObjectInputStream(sout.getInputStream()); bout.writeObject(qr); // write id info bout.writeObject(tree); qr = (takequiz)bin.readObject(); System.out.println("Response from server: code "+qr.n+", "+interp[qr.n]); sout.close(); } catch(Exception ie) { System.out.println(ie); } }//send to server public static void main(String[] argv) { int id=-1; String name = ""; try { name = argv[0]; id = Integer.parseInt(argv[1]); if (argv.length>2) SRVADDR = argv[2]; if (argv.length>3) SRVPORT = Integer.parseInt(argv[3]); if (id<700000000 || id>=800000000) throw new Exception("wrong"); } catch(Exception e) { id = -1; // signals error System.out.println("Need your name in argv[0] and Hofstra ID number in argv[1];\nSample: java takequiz \"Barna Nimal\" 702123456"); } if (id!=-1) takethequiz(name,id); }//main }//takequiz class /* Some code from the server side: this method is called to find the value (item) at a certain location in the tree. The location is indicated by a string that consists of 'l' or 'r' characters. 'l' means go left, and 'r' means go right. So 'llr' means, from the root, go left, then left again, then right. The location of the root is represented by the empty string "". If there is no vertex at the sepcified location, the function will return null. This function is used to check property 4. Since your code inherited my insert/delete methods, as long as you have implemented the AVL rotations accurately, there is only one shape and contents that your tree can have if it's correct. Integer getval(Bst2020 tree, String path) { Integer answer = null; if (path==null) return answer; Tree current = tree.root; int i = 0; while (!current.empty() && i<=path.length()) { Bst2020.vertex v = (Bst2020.vertex)current; if (i==path.length()) answer = v.item; else if (path.charAt(i)=='l') current = v.left; else if (path.charAt(i)=='r') current=v.right; else i =path.length(); i++; } return answer; } */