Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the code I have currently but I'm not getting the right output: import java.util.*; import java.io.*; public class Spell { public static void

image text in transcribed

This is the code I have currently but I'm not getting the right output:

import java.util.*;

import java.io.*;

public class Spell {

public static void main(String aa[])

{

try{

String str=null;

String str1=null;

String str2=null;

FileReader frd=new FileReader("./src./dictionary.txt");// Reading Dictionary Contents

BufferedReader brd=new BufferedReader(frd);//using buffering for file reader contnts

FileReader frt=new FileReader("./src./test.txt");// Reading Test Contents

BufferedReader brt=new BufferedReader(frt);//using buffering for file reader contnts

FileWriter ms=new FileWriter("./src./misspelled.txt");// Writing to Misspelled

BufferedWriter mst=new BufferedWriter(ms);//using buffering for file writing contnts

HashSet dict=new HashSet();//HashSet object to store dictionary data

HashSet test=new HashSet(); //store test data

while((str=brd.readLine())!=null)

{

dict.add(str.trim()); //trim to remove spacing

}

while((str1=brt.readLine())!=null)

{

StringTokenizer st = new StringTokenizer(str1," "); //string divides into tokens

while (st.hasMoreTokens()) {

test.add(st.nextToken().toLowerCase().replace('.',' ').trim());

}

}

Iterator itr=dict.iterator();

Iterator itr1=test.iterator();

test.removeAll(dict);

mst.write(test.toString());

mst.close();

System.out.println(test);

}catch(Exception ex)

{

System.out.println(ex);

}

}

}

import java.util.Iterator;

class HashSet implements Set

{

private class Node

{

private T data;

private Node next;

public Node(T item)

{

data = item;

next = null;

}

public String toString()

{

return "" + data;

}

}

public static final int DEFAULT_CAPACITY = 9;

private Node[] hashtable;

private int size;

private int items;

public HashSet ()

{

this(DEFAULT_CAPACITY);

}

@SuppressWarnings("unchecked")

public HashSet (int capacity)

{

hashtable = (Node[]) new HashSet.Node[capacity];

size = capacity;

items = 0;

}

public boolean add (T item)

{

checkForNull(item);

int index = getIndex(item);

Node current = hashtable[index];

if (current == null)

{

hashtable[index] = new Node(item);

items++;

return true;

}

while (current.next!= null)

{

if (current.data.equals(item))

{

return false;

}

current = current.next;

}

if (current.data.equals(item))

{

return false;

}

current.next = new Node(item);

items++;

return true;

}

//remove item from hashtable

public boolean remove (T item)

{

// if hash is empty, return

if (size == 0)

{

return false;

}

//check the item in hash table

for (int i = 0; i

{

Node current = hashtable[i];

do{

if(current.data.equals(item)){ //if item presents

if(current.next!=null){ //if item's next is not null

current.data=current.next.data; //replace current data with next data

current.next = current.next.next; //replace current next with next's data's next

}

else

current.data=(T) " ";

}

current=current.next;

} while(current!=null); //check for all item in the table

}

return false;

}

public T remove ()

{

return null;

}

public T get()

{

boolean filled = false;

int random = 0;

while (!filled)

{

random = (int)(Math.random() * items);

if (hashtable[random] != null)

{

filled = true;

}

}

return hashtable[random].data;

}

public boolean contains(T item)

{

int index = getIndex(item);

Node current = hashtable[index];

if (current == null)

{

return false;

}

while (current.next != null)

{

if (current.data.equals(item))

{

return true;

}

current = current.next;

}

if (current.data.equals(item))

{

return true;

}

return false;

}

public int size()

{

return size;

}

public String toString()

{

if (size == 0)

{

return "[]";

}

String h = "";

for (int i = 0; i

{

Node current = hashtable[i];

if (current == null) h+= i + "\t" + " " + " ";

else

{

h+= i + "\t" + current + " ";

while (current.next != null)

{

current = current.next;

h+= current + " ";

}

h+= " ";

}

}

return h;

}

private void checkForNull(T item)

{

if (item == null)

{

throw new IllegalArgumentException("null not a possible value!");

}

}

private int getIndex(T item)

{

int index = item.hashCode() % size;

if (index

{

index += size;

}

return index;

}

public Iterator iterator() {

// TODO Auto-generated method stub

return null;

}

public void removeAll(HashSet dict) {

// TODO Auto-generated method stub

}

}

interface Set

{

/*

* adds item to set if not already present

*

* returns true if item successfully added, false if not

*

*/

boolean add (T item);

T remove();

boolean remove (T item);

T get();

boolean contains (T item);

int size();

String toString();

}

smalldictionary.txt

aid all brown come dog for fox good is jumps lazy men now of over party quick the time to 

test.txt

Noow is the time for all good men to come to the aid of the party. The quick broawn fox jumps over the lazy sdog!!!! 

dictionary.txt

**I would post the file but it's very long since it's a list of every word in the dictionary

Thanks in advance!!

Finally, write a program Spell.java that generates a list of misspelled words for a given text. To do this, create a hash set with 1000 buckets, and load the words from dictionary.txt into it. Then check each word in the file test.txt against it. Any word not in the dictionary should be considered misspelled and written to the output file, misspelled.txt. Your program should return the following results: noow broawn sdog If you need to debug your program, use smallDictionary.txt, which contains just the twenty words in the test.txt file, change the hash table size to 5, and print it out so that you can see what it looks like internally

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago

Question

3. Did you seek anyones advice?

Answered: 1 week ago

Question

7. What traps should she avoid?

Answered: 1 week ago

Question

5. What decision-making model would you advocate to this person?

Answered: 1 week ago