/********************************************************************* Author: Dana Vrajitoru, IUSB, CS Class: C243 Data Structures File name: WordCounter.java Last updated: April 2022 Description: Implementation of the class WordCounter. **********************************************************************/ package hashTable; public class WordCounter { String word; int count; // Default constructor public WordCounter() { word = ""; count = 0; } // Constructor with value for the word, and setting the // counter to 1. WordCounter(String s) { word = s; count = 1; } // WordCounter() // Constructor with values for both attributes. WordCounter(String s, int n) { word = s; count = n; } // WordCounter() // Copy constructor WordCounter(WordCounter data) { word = data.word; count = data.count; } // WordCounter() // If we need to reset these values later. // Set the word using a String object. void setWord(String s) { word = s; } // setWord() // Set the count void setCount(int n) { count = n; } // setCount() // Copy the data from the parameter void copy(WordCounter data ) { word = data.word; count = data.count; } // copy() // Verify if the word stored in this object is equal to that String. boolean contains(String s) { return word.equals(s); } // contains() // Add 1 to the count. void increment() { ++count; } // increment() // To be used in a table. String key () { return word; } // key () // Easy output of the word counter. The parameter output can be cout. public String toString() { String s = word + " " + count; return s; } // toString() }