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

What\'s problem for this code??? import java.io.File; import java.io.FileNotFoun

ID: 3679994 • Letter: W

Question

What's problem for this code???

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Arrays;
public class Project8_ChulunDaiAndLuna {

   public static void main(String[] args) throws FileNotFoundException
   {
       Scanner input = new Scanner(System.in);
       String word = "yes";
       int filesize = findSizeOfDictionary("Dictionary.txt"); // calls method
       String[] dictionary = readFile("Dictionary.txt", filesize); // calls method
      
       while (!(word.equals("quit"))) //loop will end if "quit" entered
       {
           System.out.println("Enter a word or QUIT to stop.");
           word = input.next();
           word = word.toLowerCase();
          
           if (!(word.equals("quit"))) // doesn't run the system if "quit" is entered
           {
               spellcheck(dictionary, word);// calls method
           }
       }
       input.close();
   }
   public static int findSizeOfDictionary(String filename) throws FileNotFoundException
   {
       int count = 0;
       Scanner file = new Scanner(new File(filename));
      
       while (file.hasNextLine()) // counts the entries in the file
       {
           count++;
           file.nextLine();
       }
       file.close();
       return count; // returns number of entries
   }
   public static String[] readFile(String filename, int filesize) throws FileNotFoundException
   {
       Scanner file = new Scanner(new File(filename));
       String[] dictionary = new String[filesize]; // sets length of array
      
       for (int index = 0; index < filesize; index++) // enters words into the array
       {
           dictionary[index] = file.nextLine();
       }
       file.close();
       return dictionary;
   }
   public static void spellcheck(String[] dictionary, String word)
   {
       int searchresult = Arrays.binarySearch(dictionary, word); // gives positive value if word is found
      
       if (searchresult > -1) // returns a statement dependent upon whether word is found
       {
           System.out.println("The word is spelled correctly.");
       }
       else
       {
           System.out.println("The word is not spelled correctly.");
       }
   }
}

Explanation / Answer

Solution for the Given Question:

Give the fully qualified path for Dictionary.txt..

I don't the where this file path exit either in in your drive or some where else..

sample fully qualified path the error will remove ..

Example :

C:\Dictionary.txt"

or

C:\Users\yorrPCname\Desktop\temp1.txt

in line number 12 and 13

I checked the by giving temporary file path ..it's works fine for me without having syntax errors

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