Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone try to help me on how I can solve the error below. Do the neccessarr

ID: 3606400 • Letter: C

Question

Can someone try to help me on how I can solve the error below. Do the neccessarry changes if needed ALSO comment why you did thosechanges.

----jGRASP exec: java BinarySearchTree
C:UserslutheDocumentsScanned DocumentsDocuments (Access is denied)

----jGRASP: operation complete.

import java.util.*;
import java.io.*;
public class BinarySearchTree{
private Node root;

private static String fileInputName;

private static StringBuffer sB;

private static String fileOutputName;

private static String line;

public static void main (String [] args){
  
BinarySearchTree tree = new BinarySearchTree();

fileInputName = "C:\Users\luthe\Documents\Scanned Documents\Documents";

fileOutputName = "C:\Users\luthe\Documents\Scanned Documents\Documents Output.txt";

sB = new StringBuffer();

try {
  
File file = new File(fileInputName);
  
Scanner scan = new Scanner(file);
  
while (scan.hasNextLine()) {
  
line = scan.nextLine();
  
tree.insert(line);

}

} catch (Exception e) {
  
System.out.println(e.getMessage());
  
System.exit(0);
}
  
tree.inputUser();
  
  
/**
tree.insert("Kale");
tree.insert("Low");
tree.insert("Many");
tree.insert("Now");
tree.insert("Octopus");
tree.insert("Pear");
tree.insert("Because");
tree.insert("Candle");
tree.insert("Door");
tree.insert("Evil");
tree.insert("Face");
tree.insert("Gorge");
tree.insert("Height");
tree.insert("Indiana");
tree.insert("Joking");
tree.insert("Apple");
tree.insert("Joking");
tree.insert("Joking");
tree.insert("Joking"); */

tree.printPreOrder();
System.out.println();
tree.printInorder();
System.out.println();
tree.printPostorder();

}//main

private class Node{

private Node right;

private Node left;

private String data;

private int count;

public Node (String item){
  
data = item;
  
right = null;
  
left = null;
  
count = 0;
  
}// constructor
  
public void print() {
//System.out.println("word: " + data + ", count: " + count);

System.out.print(data + " ");
}

}

public void inputUser(){

System.out.println("Welcome to Binary Search Tree application.");

System.out.println("You will be asked to type the names of the file containing strictly words only.");

System.out.println("The application file will not accept non-letter words and all will be lowercases. ");

}//User Instructtion and his/her input to the program

// This method mainly calls insertRec()
public void insert(String word){
root = insertRec(root, word);

}

//A recursive function to insert a new key in BST.
public Node insertRec(Node node, String word){

String dublicate = null;
int count = 0;

List<Node> nodeList = new ArrayList<Node>();
  
//System.out.println(nodeList);

/* If the tree is empty, return a new node */
if (node == null) {

node = new Node(word);

return node;
}
  
int index = 0;

if(index < node.data.length()-1){

/* Otherwise, recur down the tree */
if (word.compareTo(node.data)<0)
  
node.left = insertRec(node.left, word);
  
else if (word.compareTo(node.data)>0)
  
node.right = insertRec(node.right, word);
  
}
  
for(Node nodes : nodeList){
  
if (node.data.contains(dublicate))
count++;
}

for(Node nodes : nodeList){
if (node.data.contains(dublicate))
count++;
}
  
//System.out.println("Word: " + dublicate + " " + "Count: " + count);

/* return the (unchanged) node pointer */
return node;

}// insertRec Method which takes two parameters of Root and Key.


public void insertInorderRec(Node node) {

if (node == null) {
  
return;
  
}

//recur on the left side of the tree.
if (node.left != null) {
insertInorderRec(node.left);
}
  
node.print();

//recur on the right side of the tree.
if (node.right != null) {
insertInorderRec(node.right);

}

}// printInorder method.  

public void printInorder(){

insertInorderRec(root);

System.out.print(root.data + " ");
}
  

public void insertPreOderder(Node node){

if (node == null)
  
return;

node.print();

//recur on the left subtree.

if (node.left != null) {
  
insertPreOderder(node.left);
  
}

//then recur on the right subtree.

if (node.right != null) {
  
insertPreOderder(node.right);
  
}

}// ptintPreOderder method.

public void printPreOrder(){

insertPreOderder(root);

System.out.print(root.data + " ");

}

public void insertPostorder(Node node){

if (node == null)
  
return;

// First recur on left subtree.
if (node.left != null) {
  
insertPostorder(node.left);
}

//Then recur on right subtree.

if (node.right != null) {
  
insertPostorder(node.right);
  
}

node.print();

}// printPostorder method.

public void printPostorder(){

insertPostorder(root);

System.out.print(root.data + " ");

}

public void printResult(){
try {
BufferedWriter reportFileOut = new BufferedWriter(new FileWriter(new File(fileOutputName)));
  
reportFileOut.write(sB.toString());
reportFileOut.flush();
reportFileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}

Explanation / Answer

The main problem is there is no sufficient priveleges for user to access that directory so one solution is give administrator privileges or store the data in any other drive other than C definitely your problem will be solved.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote