WordListIndexed

WordListIndexed - return...

Info icon This 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)
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern