0% found this document useful (0 votes)
17 views1 page

CGFNG

The document discusses Jack and Jill writing a Scrabble program and needing a dictionary. Jack is gathering words into a file with one word per line, starting with just seven words. Jill is coding the Java dictionary object to read in the words file and store them in a Vector when the Dictionary0 object is created.

Uploaded by

Karthikeyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

CGFNG

The document discusses Jack and Jill writing a Scrabble program and needing a dictionary. Jack is gathering words into a file with one word per line, starting with just seven words. Jill is coding the Java dictionary object to read in the words file and store them in a Vector when the Dictionary0 object is created.

Uploaded by

Karthikeyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Jack and Jill have a problem.

They are writing a software program for playing


Scrabble and they need a dictionary to look up words. The most natural way to do
this is to read in a file of words when the program first starts up. Depending on
the size of the dictionary, this file could become quite lengthy, perhaps 50,000
words. Jack's job is to gather the words into a file named words.txt, with one word
per line. He starts out with just seven words, planning to add the other 49,993
words tomorrow or the next day (Example 1-1).

Example 1-1. words.txt File

hill
fetch
pail
water
up
down
crown

Meanwhile, Jill starts coding the Java dictionary object. She uses a very
straightforward approach. When the Dictionary0 object is created, it will read in
the words from the file words.txt and store them in the Vector called "words." A
Vector is a variable-length list of items (Example 1-2).

Example 1-2: Dictionary0.java

import java.io.*;
import java.util.*;

class Dictionary0 {
Vector words = new Vector();

Dictionary0() {
loadWords();
}

void loadWords() {
try {
BufferedReader f = new BufferedReader(

You might also like