this problem contains three classes, WordData, WordDataSet, and WordDataTester. each class already contains the necessary structure.

the WordData class creates a unique word. it allows the tracking of the string word and the integer frequency of the word's usage.

  • public WordData(String w) initializes the word to w and frequency to 1
  • public void addFrequency() incrementsthe frequency count by 1
  • public String getWord() returns the actual string of the word
  • public int getFrequency() returns the word's current frequency count

so far this is my code....

public class WordData {

    private String word;
    private int frequency;

    public WordData(String w)
    {
    word = w;
    frequency = 1;
    }

    public void addFrequency(){
    frequency++;
    }
    public String getWord(){
    return word;
    }
    public int getFrequency(){
    return frequency;
    }

}

the WordDataSet class is an aggregate of WordData objects implemented with an array having a maximum size of 50. it keeps track of the total number of words entered into the set, the total number of unique words in the set, and the highest frequency count in the set.


  • so far this is my code for Wpr

  • public WordDataSet() initializes the instance fields, where all frequencies are set to 0 and the array size is the maximum
  • public void addWord(String w) checks whether the word to be added has been previously added. if yes, the existing WordData object is added to the set and its frequency is increased. otherwise, a new WordData object is created for the new word and the number of unique words is increased. if the word is successfully added to the set, the total word count increases.
  • public WordData findWord(String w) facilitates locating existing words in the set
  • public int getUniqueWords() returns the total number of unique words
  • public int getTotalWords() returns the total number of words in the set
  • public void printUpdate() prints the current total word count and total unique words
  • public String getMostFrequentWord() updates the highest frequency count and returns the string of the most frequently used word. if there are equal frequencies, the most recently added word is returned.
  • public int getMaxFrequency() returns the highest frequency count
  • public void printExit() prints the most frequently used word and its corresponding frequency count upon the application's termination

so far this is my code for WordDataSet.........

public class WordDataSet {
private int[] frequency = new int[50];
private String addWord;
private String findWord;
private String uniqueWords;
private int totalWords;
private String mostFrequentWord;
private String maxFrequency;

public WordDataSet(){
frequency[50] = 0;
}
public void addWord(String w){
addWord = w;
}

public WordData findWord(String w){


}

public String getUniqueWords(){
return uniqueWords;
}

public int getTotalWords(){
return totalWords;
}

public void printUpdate(){
System.out.println("Total Word Count: " + getTotalWords());
System.out.println("Unique Word Count: " + getUniqueWords());
}

public String getMostFrequentWord(){
return mostFrequentWord;
}

public int getMaxFrequency(){
return maxFrequency;
}

public void printExit(){
if(getMostFrequentWord() != null)
    System.out.println("Most Frequent WOrd: " + getMostFrequentWord() + "with frequency pf " + getMaxFrequency());
}
}

i ran out of ideas to public WordData findWord(String w)


test the program with the WordDataTester class

public class WordDataTester {
public static void main(String[] args){
WordDataSet words = new WordDataSet();

String[] input = { "ateneo","computer","science","ateneo", "apple",
                   "mango", "banana","ateneo","vanilla", "banana",
                   "chocolate","ateneo","java","espresso", "ateneo"};
for(int i=0;i<15;i++){
System.out.println("Word Added: " + input[i]);
words.addWord(input[i]);
words.printUpdate();}

words.printExit();
}

}
This article has been dead for over six months. Start a new discussion instead.