Question: Please fix my Java code and submit the fixed syntax. The errors say cannot find symbol BinaryTree. ************************************************************************** Compilation Errors Detected Line: 135 cannot find
Please fix my Java code and submit the fixed syntax. The errors say cannot find symbol BinaryTree.
**************************************************************************
Compilation Errors Detected
Line: 135 cannot find symbol symbol: class BinaryTree location: class Test
Line: 39 cannot find symbol symbol: class BinaryTree location: class Test
Line: 39 cannot find symbol symbol: class BinaryTree location: class Test
Line: 107 cannot find symbol symbol: variable bw location: class Test
Line: 109 cannot find symbol symbol: variable bw location: class Test
**************************************************************************
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Test {
public static void main(String[] args) throws Exception {
File file = new File("C:\\Users\\Nick\\Documents\\qz1Data.txt");
File file1 = new File("C:\\Users\\Nick\\Documents\\qz1Data.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
BufferedReader br1 = new BufferedReader(new FileReader(file1));
List list = new ArrayList();
BinaryTree tree = new BinaryTree();
try {
String st;
long millisStart = System.currentTimeMillis() % 1000;
while ((st = br.readLine()) != null) {
String arr[] = st.split(" ");
for(int i=0; i< arr.length; i++) {
list.add(Integer.parseInt(arr[i]));
}
/*bw.write(size);
bw.newLine();*/
}
long millisEnd = System.currentTimeMillis() % 1000;
System.out.println("Time taken " + (millisEnd - millisStart));
long size = getBytesFromList(list);
printInUnits(size);
String st1;
long millisStart1 = System.currentTimeMillis() % 1000;
while ((st1 = br1.readLine()) != null) {
String arr[] = st1.split(" ");
for(int i=0; i< arr.length; i++) {
tree.add(Integer.parseInt(arr[i]));
}
/*bw.write(size);
bw.newLine();*/
}
long millisEnd1 = System.currentTimeMillis() % 1000;
System.out.println("Time taken " + (millisEnd1 - millisStart1));
long size1 = getBytesFromList(tree);
printInUnits(size1);
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (bw != null)
bw.close();
} catch (Exception ex) {
System.out.println("Error in closing the BufferedWriter" + ex);
}
}
}
public static long getBytesFromList(List list) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(list);
out.close();
return baos.toByteArray().length;
}
public static long getBytesFromTree(BinaryTree tree) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(tree);
out.close();
return baos.toByteArray().length;
}
public static void printInUnits(long length) {
System.out.println("size is :: " + length + " byte");
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
