QuestionQuestion

Top 10 Scrabble Words

Goals

Leverage interface implementation to work with Java's Collections API.

Continue considering issues of efficiency/speed in programs.

Prerequisites

This assignment requires knowledge of the material presented in class through week 14 and through sections on interfaces, polymorphism, and collections in the various textbooks.

Background

Scrabble® Dictionary

Tournament Scrabble® competitions use the Official Tournament and Club Word List as an authority for valid words in a Scrabble® game.

Two relevant files exist on our server, accessible via both file path and as follow:

/srv/datasets/scrabble-hybrid is a combination of a few official Scrabble® word lists that I could find (one word per line).

/srv/datasets/scrabble-letter-values describes the value of each letter in Scrabble®.

The Comparable Interface

The Comparable interface is one of the most useful and most frequently implemented preexisting interfaces in the Java API.

For proof, see the sheer number of API classes that implement this interface.

As the API documentation states:

This interface imposes a total ordering on the objects of each class that implements it.

This ordering is referred to as the class's natural ordering, and the class's compareTo method is referred to as its natural comparison method.

Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort).

Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator.

The Comparable<T> interface consists of exactly one method, namely: int compareTo(T o)

This method:

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Assignment

You shall write a Java program that:

Reads words via standard input.

A word in standard input shall be considered a whitespace-delimited token, with any non-English-letter characters removed from the ends of the token.

Trimming those characters can be accomplished in various ways, such as:

"!@#!@$@whatever^&*^&*@#".replaceAll("^[^a-z]+|[^a-z]+$", "")

A word shall be considered valid if it is contained in the Scrabble® dictionary.

Your program shall read from the Scrabble® dictionary file and letter-value file no more than once.

Prints (up to) the 10 top-valued valid Scrabble® words, one word per line:

Words shall be printed in descending order of their point values.

Any ties shall be broken in lexicographic order.

Words shall be printed in uppercase, to reflect that they are Scrabble® words.

If there are fewer than 10 valid words in the input, all of the valid words shall be printed.

Suggestions

This assignment shouldn't be too hard if you:

Develop a class that represents a Scrabble® word, and is able to instances of itself such that sorting a Collection of them will result in the top/bottom-valued words, with ties broken lexicographically.

The class could also maintain a static Collection of the valid Scrabble® words, in order to verify that a word is valid.

Read all words from standard input, and create an appropriate type of Collection of objects using your class.

You can then sort the Collection, or use a Collection type that is already sorted.

The only remaining work is to print the first (or last) up-to-10 elements.

Examples

For example:

'be here now'

HERE

NOW

BE

QUICK

HEMLOCK

TREACHERY

ANYBODY

INCOMPLETE

PREACHERS

UNDERSTANDING

ABSURDITY

ANYTHING

POVERTY

QUALIFICATION

RECOGNIZANCE

ACQUAINTANCE

CATECHIZE

CIRCUMSCRIPTION

EXCEEDINGLY

EXQUISITE

QUICKLY

COLOQUINTIDA

CONSEQUENCE

RAZZAMATAZZES

RAZZMATAZZES

PIZZAZZY

RAZZAMATAZZ

RAZZMATAZZ

BAZZAZZES

BEZZAZZES

PAZZAZZES

PIZZAZZES

QUIZZIFICATIONS

Solution PreviewSolution 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.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;

/*
* Scrabble Sort class
*/
public class cs12j_scrabble_sort {
   
    public static final String SCRABBLE_WORDS_FILE = "scrabble-hybrid.txt";
    public static final String LETTER_VALUES_FILE = "letter-values.txt";
   
    // Main method for program execution
    public static void main(String[] args) {
      
       /*...

By purchasing this solution you'll be able to access the following files:
Letter-values.txt, Genius.txt, Othello.txt, Scrabble-hybrid.txt and Solution.java.

$30.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats