Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

** following is the project 1 that I've done. Now i need help with the following. This project builds on project 1. Queens College, CUNY

** following is the project 1 that I've done. Now i need help with the following.

This project builds on project 1.

Queens College, CUNY Department of Computer Science

CSCI 212 Project 2 Spring 2016

There should now be three columns in the project GUI: text from an unsorted array, text from a sorted array and text from a sorted linked list. When the program starts, the input file should be read into two arrays, and one of the arrays is then sorted as usual. Each time a word is read from the file, it is inserted in the linked list in the proper position to keep the list in sorted order. When all the words have been read, then the text areas are to be filled and displayed in the GUI.

Now your program can start accepting commands. A JOptionPane input dialog should pop up and say Enter Command:. The valid commands are ADD, DELETE, and STOP (upper or lower case). The command ADD should be followed by a space, and then a list of one or more words separated by commas. These words are to be added to the arrays and the linked list and displayed in the GUI. The command DELETE should be followed by a space and a single word to be deleted (again, the displays should be updated). Note that the word to be deleted might not be in the arrays or the list! The command STOP means stop the program.

// Project1.java import java.io.*; public class Project1 { public static void main(String[] args) throws FileNotFoundException { Project1GUI gui = new Project1GUI("Valid Words"); } }

// Project1GUI.java import java.io.*; import java.awt.*; import java.util.*; import javax.swing.*; public class Project1GUI extends JFrame { private final int MAX = 100; private JTextArea left = new JTextArea(); private JTextArea right = new JTextArea(); public Project1GUI(String title) throws FileNotFoundException { setTitle(title); setSize(400, 400); setLayout(new GridLayout(1, 2, 10, 10)); add(left); add(right); String[] words = new String[MAX]; int count = readFile(words); for(int i = 0; i < count; i++) { left.append(words[i] + " "); } sortWords(words, count); for(int i = 0; i < count; i++) { right.append(words[i] + " "); } setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }

public int readFile(String[] words) throws FileNotFoundException { Scanner infile = new Scanner(new File("words.txt")); String str; int count = 0; while(infile.hasNext() && count < MAX) { str = infile.next(); if(isValidWord(str)) { words[count] = str; count++; } } infile.close(); return count; }

public boolean isValidWord(String str) { for(int i = 0; i < str.length(); i++) { if(!Character.isAlphabetic(str.charAt(i))) return false; } return true; } public void sortWords(String[] words, int count) { for(int i = 0 ; i < count - 1; i++) { int minPos = i; for (int j = i + 1 ; j < count ; j++ ) { if (words[j].compareTo(words[minPos]) < 0) minPos = j; } if ( minPos != i ) { String swap = words[i]; words[i] = words[minPos]; words[minPos] = swap; } } } }

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago