Question: ` ` ` public static void main ( String [ ] args ) throws AVLTreeException, IOException { String usage = Harvester % n ;
public static void mainString args throws AVLTreeException, IOException
String usage "Harvester n;
usage "The command file name is entered as a command line argumet.n;
usage "The command file consists of instructions in one of these formats:.n;
usage "insert n;
usage "remove n;
usage "traversen;
usage "props";
if argslength
System.out.printfusage;
System.exit;
Read the command file
String fileName args;
FileReader fileReader new FileReaderfileName;
Scanner scanner new ScannerfileReader;
Instantiate the tree using the default constructor
AVLTree avlTree new AVLTree;
Instantiate the tree using a comparator that compares strings first by length,
and if lengths are the same, then lexicographically
Comparator comparator new Comparators
@Override
public int compareString s String s
int lenDiff Integer.compareslength slength;
if lenDiff
return lenDiff;
return scompareTos; Lexicographical comparison if lengths are equal
;
AVLTree avlTree new AVLTreecomparator;
while scannerhasNextLine
String line scanner.nextLinetrim;
if lineisEmpty continue; Skip empty lines
String parts line.splits;
String command parts;
switch commandtoLowerCase
case "insert":
if partslength
System.out.printfError: Invalid insert command format.n;
continue;
String wordToInsert parts;
System.out.printfInserting sn wordToInsert;
avlTree.insertwordToInsert;
break;
case "remove":
if partslength
System.out.printfError: Invalid remove command format.n;
continue;
String wordToRemove parts;
System.out.printfRemoving sn wordToRemove;
avlTree.removewordToRemove;
break;
case "traverse":
System.out.printlnInorder traversal of the AVL Tree:";
implement this method for
break;
case "props":
System.out.printfNumber of elements in AVL tree: dn avlTree.size;
System.out.printfHeight of the AVL tree: dn avlTree.height;
break;
default:
System.out.printfError: Unknown command sn command;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
