The words will be arranged in alphabetical order from a to z What is the best so
ID: 3659610 • Letter: T
Question
The words will be arranged in alphabetical order from a to z What is the best sorting method? how to use a sorting algorithm for this program? should i use a second hash table in this same class? main objective: -Display the results in descending order of frequency of occurrence. -Add a second hash table that will hold large words. For the purpose of this assignment we will define large words as those words that contain more than six letters. The large words should be placed in both the original hash table and the large word hash table. The user should be given the option to display the contents of the entire large word hash table. i tried to use bubble sorting but refuse to work correctly! import java.awt.*; //tools to be added import java.awt.event.*; import javax.swing.*; import javax.swing.filechooser.*; import java.util.*; import java.io.*; public class Concordance extends JFrame{ private JButton chooser, start; private JLabel wordLabel; private JTextField wordField; private JPanel inputPanel; private JTextArea results; private File inFile; private String inputFileName; private Dictionary concordanceTable; //instantiating a hash table public static void main () { Concordance myFrame = new Concordance(); myFrame.setSize(500,500); myFrame.setTitle("Concordance"); myFrame.createGUI(); myFrame.setVisible(true); } private void createGUI (){ setDefaultCloseOperation(EXIT_ON_CLOSE); Container window = getContentPane(); window.setLayout(new FlowLayout()); inputPanel = new JPanel(); inputPanel.setLayout(new BoxLayout (inputPanel, BoxLayout.X_AXIS)); inputPanel.add(Box.createRigidArea (new Dimension(20,40))); chooser = new JButton("Select File"); //chooser button chooser.addActionListener(new ChooserAction()); inputPanel.add(chooser); inputPanel.add(Box.createRigidArea (new Dimension(20,40))); wordLabel = new JLabel("Word "); inputPanel.add(wordLabel); wordField = new JTextField(12); inputPanel.add(wordField); inputPanel.add(Box.createRigidArea(new Dimension(20,40))); start = new JButton("Start"); //start button start.addActionListener(new StartAction()); inputPanel.add(start); window.add(inputPanel); results = new JTextArea(25,30); //display the text JScrollPane scrollPane = new JScrollPane(results); window.add(scrollPane); } private class ChooserAction implements ActionListener{ public void actionPerformed (ActionEvent e){ JFileChooser myChooser = new JFileChooser(); int returnValue = myChooser.showOpenDialog(Concordance.this); inputFileName = myChooser.getSelectedFile().getName(); inFile = myChooser.getSelectedFile(); } } private class StartAction implements ActionListener{ public void actionPerformed (ActionEvent e){ if (inputFileName != null){ buildConcordance(); }else{ JOptionPane.showMessageDialog(null,"Please select a file first", "Error", JOptionPane.ERROR_MESSAGE); } } } public void buildConcordance(){ // hashtable description what to do if error occurs concordanceTable = new Hashtable (); try{ //error bypass readLines(new BufferedReader(new FileReader(inFile))); //read the file that has text generateOutput( ); } catch (IOException event){ JOptionPane.showMessage Dialog (null, "Can not open/read file" + inputFileName, "Error", JOptionPane.ERROR_MESSAGE); } //if it is not a file and empty it will display an error message } public void readLines(BufferedReader input) throws IOException{ String delimeters = " .,!?;:"; //skips all the symbols that is found for(int lines = 1; true; lines++){ //get words String lineText = input.readLine(); if(lineText == null) return; lineText = lineText.toLowerCase(); //enter the words Enumeration e = new StringTokenizer(lineText, delimeters); while(e.hasMoreElements()){ enterWord( (String) e.nextElement()); //define enter Word in method to be located as a string of word } } } public void enterWord(String theWord){ Integer count; //value count = concordanceTable.get(theWord); //it will obtain word in notepad to be calculated if (count == null){ //if table is empty concordanceTable.put(theWord, 1); }else{ concordanceTable.put(theWord, count+1); //theWord object will be placed on table and will add a number to it } } public void generateOutput(Integer numberWords, Integer numberCharacters){ String theWord = ""; //add String Integer wordFrequency = 0; numberWords=0; numberCharacters=0; //calculations Enumeration e = concordanceTable.keys(); //words are placed as keys to be sorted results.append(" Concordance for " + inputFileName + " "); while(e.hasMoreElements()){ theWord = (String) e.nextElement(); wordFrequency = concordanceTable.get(theWord); numberWords += wordFrequency; wordFrequency += theWord.length()*wordFrequency; } results.append("the average word length is " + wordFrequency/numberWords + " "); } } ----------------------------------------------------------------------------------------- sorting algorithm i've use public static void bubbleSort4(int[] x) { int newLowest = 0; // index of first comparison int newHighest = x.length-1; // index of last comparison while (newLowest < newHighest) { int highest = newHighest; int lowest = newLowest; newLowest = x.length; // start higher than any legal index for (int i=lowest; i x[i+1]) { // exchange elements int temp = x[i]; x[i] = x[i+1]; x[i+1] = temp; if (i< 0) { newLowest = 0; } } else if (i>newHighest) { newHighest = i+1; } } } }Explanation / Answer
post the program with proper indentation :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.