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

import java.io.File; importjava.io.IOException; import java.util.Scanner; public

ID: 3615815 • Letter: I

Question

import java.io.File;

importjava.io.IOException;

import java.util.Scanner;

public class SpellCheck {

                public static void main(String[] args) throwsIOException {

                                Scanner dictionary = new Scanner(newFile(args[0]));

                                Scanner size = dictionary;

                                int numWords = 0;

                                while (size.hasNext()) {

                                                numWords++;

                                                size.next();

                                }

                                int count = 0;

                                String[] words = newString[numWords];

                                while (dictionary.hasNext()) {

                                                words[count] =dictionary.next();

                                                count++;

                                }

                                System.out.println("What file doyou wish to spell check? Or type quit when done.");

                                Scanner document = newScanner(System.in);

                                String w = document.next();

                                String [] mispelled = new String[10];

                                       

                                while (!w.equalsIgnoreCase("quit")){

                                                Scanner in = newScanner(new File(w));

                                                int j;

                                                while (in.hasNext()){

                                                                Stringword = in.next();

                                                          

Explanation / Answer

Well the first part is plain and simple, the program just reads inthe dictionary file and assigns each word to a position in anarray. Then the second part is asking the user to enter in afile name or type quit to stop the program. It then scans thenext thing entered in by the user and returns it as a string. That string, if not "quit", is then considered a file name then theprogram creates a new file and then scans it. And now we aregetting to the place where your program starts to haveproblems. You want it to then read each word in the file andif it's not in the dictionary, add it to an array calledmispelled. After the file has been completely read, then youwant to display all the misspelled words. Then ask the useragain for another file or to type in quit to stop theprogram. The first problem is that the part where it is checking the wordsis messed up. Another problem is that I wouldn't use an arrayfor mispelled. I would use an arraylist, because in realityyou don't know how many misspelled words a file will have init. If you use an array with 10 spots and you have more than10 misspelled words, you will get an ArrayOutOfBoundsexception. Also, you will have to have the output statementsof how many misspelled words there are in the file and also askingthe user for another file or type quit inside the first while loop,or it will not work properly. I edited your code a littlebit:         while(!w.equalsIgnoreCase("quit")) { //While w does not equal"quit".            Scanner in = new Scanner(new File(w)); //Scan the newfile.            ArrayList mispelled = newArrayList();            while (in.hasNext()) { //While there are words still left inthe file.                String word = in.next(); //Get the next word.                //Check to see if the word is in the dictionary.                //If it is not, add it to mispelled.                //If it is in the dictionary, then break from loop.                for (int j = 0; j
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote