Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

CISS-111 Project 6

Posted on March 26, 2013May 1, 2025 By William Jojo
CISS-111-Project
CISS-111 Project 6

Write a Java program to demonstrate using hash tables. Doing more file processing, you will read in a dictionary file, dictionary.txt, and use its contents to spell check a file, checkme.txt, that is provided on the command line.


Learning outcomes

  • Working with Hash Tables.
  • Establishing a working hash method to guarantee consistency.
  • Combining arrays and linked lists in a new way to produce a more efficient data structure.
  • Working with multiple files.
  • Confirmation program produces desired results.

This project is not an in-depth, comprehensive program on the nature of root words, tenses, plurals, or endings. Rather many words of the varying form (plurals, possessives) will be provided in the dictionary file.

You will need to create two Java files: Project6_lastname.java and StringHash.java.

Given:

  • A dictionary.txt file of 125,000+ dictionary words.
  • A checkme.txt file to be spell checked provided on the command line.
  • A hash function from Chapter 15 and a bucket value of 2000 passed to the constructor.

Create a StringHash class based on the DirectChainLoadFactor class in Chapter 15.


Now create a Project6 class for testing the StringHash class. This class will also have your main() method. Use the following in the Project6 class:

public static String removeNonLetDig(String s) {
    int b = 0, e = s.length()-1;
     
    // Trim from the beginning
    while (b <= e && !Character.isLetterOrDigit(s.charAt(b)))
      b++;
     
    // Trim from the end
    while (e >= b && !Character.isLetterOrDigit(s.charAt(e)))
      e--;
     
    if (b <= e)
      return s.substring(b,e + 1);
    else
      return null;
  }

Note: this is from the Short-Circuit discussion.

The remainder of this work should be done in the Project6 class.

Your input file will be given on the command line. The dictionary file should be hardcoded as dictionary.txt.

Read the dictionary file into the hash table using an EOF loop and the put() method.

*NOTE*: You must either lower case or upper case the words as they are entered into the hash table.

Lookups will be consistent later as you must do the same when you request a word lookup using get().

After the hash table is populated with the dictionary words, open the file to be spell-checked and read words from the file one at a time. Check the word against the hash table using get() after invoking removeNonLetDig().

A few additional notes to make life easier:

  • A null reference returned by removeNonLetDig() is a valid word (because there is no longer a word).
  • The removeNonLetDig() method is designed to remove surrounding punctuation on a word. Since we can use the next() Scanner method to read a word from the file, white-space is not a problem, but a word at the end of a sentence or part of a quotation may have leading or trailing non-letter or non-digit characters.

Display to standard output those words that are not spelled correctly or do not appear in the hash table. Your output should look exactly like:

specialized
yacc.c
bison.simple
C
LALR(1
lalr1.cc
C
bison-patches@gnu.org
glr.c
Generalized
LR
C
LALR(1
C
2002
and/or
2
59
330
02111-1307

Submit the project to the Learning Management System as Project6_lastname.java, and StringHash.java.

Post navigation

❮ Previous Post: Ubuntu Topic 3 – Bash Shell Scripting
Next Post: CISS-111 Extra Credit Lists ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.