Word.java
package edu.odu.cs.cs350;
/**
* Represents a single word and its frequency count in a document.
*
* Each {@code Word} object stores the word itself and the number of times
* it has appeared. This is useful for calculating term frequency (TF) and
* other text analysis metrics.
*
*/
public class Word {
/** The word as a string. */
private String word;
/** The number of times this word has been counted. */
private int count;
/**
* Constructs a new Word with an initial count of 1.
*
* @param word the string representation of the word
*/
public Word(String word) {
this.word = word;
this.count = 1; // first occurrence
}
/**
* Returns the string representation of this word.
*
* @return the word as a string
*/
public String getWord() {
return word;
}
/**
* Returns the current count of occurrences for this word.
*
* @return the count of occurrences
*/
public int getCount() {
return count;
}
/**
* Increments the count of occurrences for this word by 1.
*/
public void incrementCount() {
count++;
}
}