Question: package com.project.CS3345Tree; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; class Book{ int ISBN; public Book(int iSBN2){ ISBN = iSBN2; } } class AVLNode { AVLNode left,
package com.project.CS3345Tree; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; class Book{ int ISBN; public Book(int iSBN2){ ISBN = iSBN2; } } class AVLNode { AVLNode left, right; Book book; int height; /*Constructor */ public AVLNode(Book book) { left = null; right = null; this.book = book; height = 0; } } /* AVL Tree */ class AVLTree { private AVLNode root; /* Constructor */ public AVLTree() { root = null; } /* Insert into the Tree */ public void insert(Book book) { root = insert(book, root); } private int height(AVLNode t) { return t == null ? -1 : t.height; } private int max(int lhs, int rhs) { return lhs > rhs ? lhs : rhs; } /* Find the height of the Tree */ private AVLNode insert(Book book, AVLNode top) { if(top == null) top = new AVLNode(book); else if(book.ISBN < top.book.ISBN) { top.left = insert(book,top.left); if(height(top.left) - height(top .right) == 2) { System.out.print("Imbalance occurred at inserting ISBN " + book.ISBN); if(book.ISBN < top.left.book.ISBN) { System.out.println("; fixed in Left Rotation"); top = rotateWithLeftChild(top); } else { System.out.println("; fixed in RightLeft Rotation"); top = doubleWithLeftChild(top); } } } else if (book.ISBN > top.book.ISBN) { top.right = insert(book, top .right); if (height(top.right) - height(top.left) == 2) { System.out.print("Imbalance occured at inserting ISBN" + book.ISBN); if (book.ISBN > top.right.book.ISBN) { System.out.println("; fixed in Right Rotation"); top = rotateWithRightChild(top); } else { System.out.println("; fixed in LeftRight Rotation"); top = doubleWithRightChild(top); } } } top.height = max(height(top.left), height(top.right)) + 1; return top; } private AVLNode rotateWithLeftChild(AVLNode k2) { AVLNode k1 = k2.left; k2.left = k1.right; k1.right = k2; k2.height = max(height(k2.left), height(k2.right)) + 1; k1.height = max(height(k1.left), k2.height) + 1; return k1; } private AVLNode rotateWithRightChild(AVLNode k1) { AVLNode k2 = k1.right; k1.right = k2.left; k2.left = k1; k1.height = max(height(k1.left), height(k1.right)) + 1; k2.height = max(height(k2.right), k1.height) + 1; return k2; } private AVLNode doubleWithLeftChild(AVLNode k3) { k3.left = rotateWithRightChild(k3.left); return rotateWithLeftChild(k3); } private AVLNode doubleWithRightChild(AVLNode k1) { k1.right = rotateWithLeftChild(k1.right); return rotateWithRightChild(k1); } public void inorder() { inorder(root); } private void inorder(AVLNode r) { if (r != null) { inorder(r.left); System.out.print(r.book.ISBN + " "); inorder(r.right); } } } public class AVLTreeTest { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File("books.txt")); AVLTree avlt = new AVLTree(); while (in.hasNextLine()) { Book book = new Book(in.nextInt()); avlt.insert(book); } System.out.print(" In order: "); avlt.inorder(); in.close(); } } /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/lib/tools.jar:/Users/mlagrone1/Desktop/Java_Projects/out/production/Java_Projects com.project.CS3345Tree.AVLTreeTest Exception in thread "main" java.io.FileNotFoundException: books.txt (No such file or directory) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.
Process finished with exit code 1
// Used code from chegg, receiving this error need help resolving the issue.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
