Question
Question 1(60 Marks)
Write a GUI application to insert N
numbers into a binary search tree. Your program should have the option to either read the input from an input file or to generate N random numbers (based on user request).
Your program should have the following features:
•display the height of the binary search tree
•find the kth smallest element, where kis an input
•sort the input in both ascending and descending orders (based on user request)
•display the original (unsorted list) and the final sorted lists Display all output in a scrollable text area. Do not use any arrays in your program.

Question 2(40 Marks)
Write a GUI program that reads an input text file (use JFileChooser class to get the name of the input file), and then generates an output file containing the words from the input file in ascending alphabetical order. The input file can be any text file. You should identify individual words and avoid spaces and punctuations.
-You are required to use a heap with the min-heap property to solve this problem.
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

--question #1
   require: BST.java Node.java Question1.java
   compile : javac Question1.java
   run : java Question1

--question #2
   require: Heap.java Question2.java
   compile : javac Question2.java
   run : java Question2

import java.awt.HeadlessException;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
*
* @author
*/
public class Question1 extends JFrame {
   
    private JScrollPane jScrollPane1;
    private JTextArea textArea;

    /**
    * constructor
    * @param mes string to be showed
    * @throws HeadlessException
    */
    public Question1(String mes) throws HeadlessException {
       super("Question 1");
       textArea = new JTextArea(mes);
       jScrollPane1 = new JScrollPane(textArea);
      
       add(jScrollPane1);
       pack();
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setVisible(true);
    }
   
   
    /**
    * main function
    * @param args
    */
    public static void main(String[] args) {
       Object[] options = {"Read from file",
            "Generate numbers"};
       int n = JOptionPane.showOptionDialog(null,
                "What action do you want to take?",
                "Question 1",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]);
      
       BST bst ;
      
       if (n == 0) {
            bst = fromFile();
       } else {
            bst = generate();
       }
      
       int k = 0;
       try {
            String num = JOptionPane.showInputDialog(null,
                        "Ente k value: ");
                k = Integer.parseInt(num);
       } catch (Exception e) {
            k = 0;
       }
      
       String mes = "";
       mes += "Height of the binary search tree "
                + bst.height() + System.lineSeparator();
       ArrayList<Integer> al = bst.k_smallest(k);
      
       mes += k + "th smallest element: " + al.toString()
                + System.lineSeparator();
      
       Object[] options1 = {"Ascending",
            "Descending"};
       n = JOptionPane.showOptionDialog(null,
                "Which order of input do you want to show?",
                "Question 1",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options1,
                options1[0]);
      
       ArrayList<Integer> ll;
       if (n == 0) {
            ll = bst.ascending();
            mes += "Ascending order: ";
       } else {
            ll = bst.descending();
            mes += "Ascending order: ";
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
solution.zip
Purchase Solution
$74.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 641 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,803+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,660+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,421+ sessions)
2 hours avg response

Similar Homework Solutions