WordListIndexed

WordListIndexed - return...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; public class WordListIndexed implements ImpWordList { WordList wordListsIndexed[]; int numIndex = 10; int hiLength = numIndex - 1; public WordListIndexed() { wordListsIndexed = new WordList[numIndex]; } public boolean add(String theWord) { if (theWord.length() >= numIndex) { wordListsIndexed[hiLength].add(theWord); } else wordListsIndexed[theWord.length() - 1].add(theWord); return true; } public void clear() { for (int i = 0; i < wordListsIndexed.length; i++) wordListsIndexed[i].clear(); } public boolean contains(String theWord) { if (theWord.length() >= numIndex)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return wordListsIndexed[hiLength].contains(theWord); else return wordListsIndexed[theWord.length() - 1].contains(theWord); } public void readFile(String fileName) throws FileNotFoundException { Scanner inp = new Scanner(new File(fileName)); while (inp.hasNext()) { String line = inp.nextLine(); String word = line.split(" "); for (int i = 0; i < word.length; i++) { if (word[i].trim().length() >= numIndex) wordListsIndexed[hiLength].add(word[i].trim()); else wordListsIndexed[word[i].trim().length() - 1].add(word[i] .trim()); } } } public int size() { int num = 0; for (int j = 0; j < wordListsIndexed.length; j++) num = num + wordListsIndexed[j].size(); return num; } }...
View Full Document

This note was uploaded on 06/10/2011 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Page1 / 2

WordListIndexed - return...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online