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

This is a JSFiddle assignment and must be completed at jsfiddle.net and include

ID: 3576239 • Letter: T

Question

This is a JSFiddle assignment and must be completed at jsfiddle.net and include both the HTML and Java sections

Implement a TRIE that has both the functions AddToTRIE and CheckSpelling.

Once you have created the TRIE add the words (hard code) I, in, into, inlet, inn, inner, innate, ink. These are good words to use to test your TRIE

Create an interface that has one text box for entry and 2 buttons - Add To Dictionary and Spell Check. They should ad the word to the TRIE (feedback - word added) and check the word against the TRIE and return in the word was in or not in the dictionary.

Explanation / Answer

import java.util.*;

import java.io.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.event.*;

public class SpellCheck {

                JFrame theFrame;

                JTextArea spellArea;

                JTextArea fileArea;

                String file;

                int caretPosition;

                static Set dictionary;

                static Set myDictionary;

                final String ALPHABET = "This is Demo";

                final String DELIMITERS = " I, in, into, inlet, inn, inner, innate, ink.";

              public SpellCheck() {

                                theFrame = new JFrame("Spell Checker");

                                Toolkit tk = Toolkit.getDefaultToolkit();

                                int width = 2*(int)(tk.getScreenSize().getWidth())/3;

                                int height = 2*(int)(tk.getScreenSize().getHeight())/3;

                                theFrame.setSize(width,height);

                                theFrame.setLocation(width/6,height/6);

                                theFrame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,width,20));

                                JLabel spellLabel = new JLabel("Possible replacement words. Select the word used as the replacement");

                                spellArea = new JTextArea(5,100);

                                spellArea.setFont(new Font("Courier",Font.BOLD,12));

                                JPanel spellPanel = new JPanel(new BorderLayout());

                                spellPanel.add(spellLabel,"North");

                                spellPanel.add(spellArea);

                                JScrollPane spellPane = new JScrollPane(spellPanel);

                                JLabel fileLabel = new JLabel("Text Area");

                                fileArea = new JTextArea(15,100);

                                fileArea.requestFocus();

                                fileArea.setFont(new Font("Courier",Font.BOLD,12));

                                fileArea.setEditable(false);

                                JPanel filePanel = new JPanel(new BorderLayout());

                                filePanel.add(fileLabel,"North");

                                filePanel.add(fileArea);

                                JScrollPane filePane = new JScrollPane(filePanel);

                                JButton openButton = new JButton("Open File");

                                JButton saveButton = new JButton("Save File");

                                JPanel buttonPanel = new JPanel(new BorderLayout());

                                JButton spellCheckButton = new JButton("Spell Check");

                                JButton replaceButton = new JButton("Replace Word");

                                JButton addButton = new JButton("Add Word to Dictionary");

                                buttonPanel.add(openButton,"North");

                                buttonPanel.add(spellCheckButton,"West");

                                buttonPanel.add(replaceButton,"Center");

                                buttonPanel.add(addButton,"East");

                                buttonPanel.add(saveButton,"South");

                                theFrame.getContentPane().add(buttonPanel);

                                theFrame.getContentPane().add(filePane);

                                theFrame.getContentPane().add(spellPane);

                                fileArea.getCaret().setSelectionVisible(true);

                                spellArea.getCaret().setSelectionVisible(true);

                                openButton.addActionListener(new OpenFileAction());

                                spellCheckButton.addActionListener(new SpellCheckAction());

                                saveButton.addActionListener(new SaveAction());

                                addButton.addActionListener(new AddAction());

                                replaceButton.addActionListener(new ReplaceAction());

                                theFrame.addWindowListener( new WindowClosingAction());

                                theFrame.setVisible(true);

                }

              class OpenFileAction implements ActionListener {

                              public void actionPerformed(ActionEvent e) {

                                                JFileChooser openDir = new JFileChooser();

                                               

                                                openDir.setCurrentDirectory(new File("C:\data\"));

                                                openDir.setSelectedFile(new File("spellTest.txt"));

                                                int result = openDir.showOpenDialog(theFrame);

                                                File theFile = openDir.getSelectedFile();

                                                fileArea.setEditable(true);

                                               

                                                fileArea.setEditable(false);

                                }

                }

                class SpellCheckAction implements ActionListener {

                                public void actionPerformed(ActionEvent e) {

                                               

                                }

                }

               

                               

                class SaveAction implements ActionListener {

                                public void actionPerformed(ActionEvent e) {

                                                JFileChooser saveDir = new JFileChooser();

                                               

                                                saveDir.setCurrentDirectory(new File("C:\DirectoryWhereFileIs\"));

                                                saveDir.setSelectedFile(new File("C:\DirectoryWhereFileIs\SpellCheckerTestFile.txt"));

                                                int result = saveDir.showSaveDialog(theFrame);

                                                File theFile = saveDir.getSelectedFile();

                                               

                                }

                }

                class AddAction implements ActionListener {

                                public void actionPerformed(ActionEvent e) {

                                               

                                }

                }

                class ReplaceAction implements ActionListener {

                                public void actionPerformed(ActionEvent e) {

                                                fileArea.setEditable(true);

                                               

                                                fileArea.setEditable(false);

                                }

                }

                class WindowClosingAction extends WindowAdapter {

                                public void windowClosing(WindowEvent e) {

                                               

                                }

                }

               

                public static void main(String[] args) throws IOException {

                                dictionary = new HashSet();

                                myDictionary = new HashSet();

                                BufferedReader din = new BufferedReader(new FileReader("dictionary.txt"));

                                String aWord;

                                System.out.println("Loading Dictionary...");

                                while( (aWord = din.readLine() ) != null ) {

                                                dictionary.add(aWord);

                                }

                                try {

                                                din = new BufferedReader(new FileReader("myDictionary.txt"));

                                } catch( FileNotFoundException e4 ) {

                                                new FileWriter("myDictionary.txt");

                                                din = new BufferedReader(new FileReader("myDictionary.txt"));

                                }

                                while( (aWord = din.readLine() ) != null ) {

                                                myDictionary.add(aWord);

                                }

                                dictionary.addAll(myDictionary);

                                new SpellCheck();

                }

}

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