Creating a program that will read from a file

Use Eclipse Java program!!!

Concepts tested by this program:

  • Create a Comparator
  • Create a TreeSet using a comparator
  • Collections.sort using a comparator
  • Use a generic class
  • JTable – select a row

You will be creating a program that will read from a file. For each sentence, the word with the largest Scrabble value and the Scrabble value for that word will be displayed.

The Scrabble values are as follows:

  • 1 point: E, A, I, O, N, R, T, L, S, U
  • 2 points: D, G
  • 3 points: B, C, M, P
  • 4 points: F, H, V, W, Y
  • 5 points: K
  • 8 points: J, X
  • 10 points: Q, Z

Comparataor - ScrabbleComparator

Create a ScrabbleComparator that implements Comparator<String>. The compare will sort the strings in reverse order by Scrabble Value. The largest value will be first.

Data Structure - TreeSet. Construct the TreeSet with the ScrabbleComparator. Use for getLargest. All words are added to the TreeSet. The largest is retrieved with the first method.

Creating a program that will read from a file Image 1

Data Manager/Utility classes

  1. Create a ScrabbleUtility class with the following static methods:
    1. String getLargest(String). Determines the largest scrabble value of words in a Sentence and returns the word (String) with the largest scrabble This method will store the words of the string into a TreeSet constructed with the ScrabbleComparator.
    2. TreeSet getLargest(String, int). This method will store the words of the string into a TreeSet constructed with the ScrabbleComparator and return the TreeSet This method is for testing purposes only.
    3. int getScrabbleValue(String). Determines the scrabble value of the string and returns the value.
    4. ArrayList<Pair<String, Integer>> getScrabbleValues(String). Determines the scrabble value of each word in the String and returns an ArrayList of Pairs. Each Pair contains the word(a String) and the Scrabble value (an Integer). Use the Pair<T,S> class provided. The first word in the string will be represented by the first Pair in the ArrayList. The fifth word in the string will be represented by the fifth Pair in the ArrayList.
    5. ArrayList<Pair<String, Integer>> sortScrabbleValues(String). Determines the scrabble value of each word in the String, sorts them in Scrabble Order and returns an ArrayList of Pairs. Each Pair contains the word(String) and the Scrabble value (Integer). Use the Pair<T,S> class provided. Use the Collections.sort with the comparator that sorts in Scrabble Order.

The GUI

If the user selects the Read Text File button, use the JFileChooser to ask the user for the location of the text file to be read and then display the contents of the file in a table. Use a table so that a row of the table can be selected.

If the user selects the Largest Scrabble Value button, display the largest word and the scrabble value for each sentence.

If the user selects a row in the table and the All Scrabble Values in Sentence button, display all the words in that sentence with their scrabble values. If the user selects the Sort in Scrabble Order button, the words of the sentence and their scrabble values are displayed with the largest scrabble value word first.

You can assume that the files are correct and there is one sentence per line.

Creating a program that will read from a file Image 2

Disable Largest Scrabble Value button until user Selects Read Text File Button.

Read Text File

Use JFileChooser to allow user to select text file. Read from text file and place into Table.

Enable the Largest Scrabble Value Button

Creating a program that will read from a file Image 3

Disable All Scrabble Values in Sentence button until user selects a row in the table.

Results of Largest Scrabble Value:

Creating a program that will read from a file Image 4

When user selects a row in the table, the All Scrabble Values in Sentence button becomes enabled

Creating a program that will read from a file Image 5

Results of All Scrabble Values in Sentence:

Creating a program that will read from a file Image 6

Sort in Scrabble Order button becomes visible.

Results of Sort in Scrabble Order:

Creating a program that will read from a file Image 7

DOCUMENTATION

Javadoc for user created classes: 4 pt____

Test Cases 4 pt____

JUnit Test Class

Implement the student test methods of the ScrabbleUtility

UML Diagram 2 pt ____

PROGRAMMING

Programming Style

Internal class documentation (within source code) 5 pt ___

Class description using Javadoc

Author’s Name, Class, Class Time

Methods commented using Javadoc

Program user interface

Clear to user how data is to be entered 1 pt____

Output is easy to understand 1 pt____

Accuracy

Public tests (those I gave you and your additions) 5 pt ____

Private tests 5 pt ____

Program Details

  1. ScrabbleComparator class 6 pt _____
    1. Implements Comparator<String>
    2. Sorts in reverse order on Scrabble Value
  2. ScrabbleUtility class 10 pt _____
    1. getLargest – uses TreeSet and Comparator

returns the largest String in the TreeSet

  1. getScrabbleValue – returns the scrabble value for a string
  2. getScrabbleValues – returns pairs of words and scrabble values

for each of the words in the string

  1. sortScrabbleValues - uses Collections.sort and Comparator to sort

by ScrabbleValue, returns pairs of words and scrabble values for

each of the words in the string

  1. GUI classes 7 pt _____
    1. Uses FileChooser to select text file
    2. Reads from a file and puts contents in a table
    3. Uses the methods of the ScrabbleUtility
    4. Buttons are enabled when appropriate
    5. User can select one row of the table

Total 50 pt _____

Comments: