You will implement a class called BagOfWords . You will receive points for each JUnit test you
Question:
You will implement a class called BagOfWords. You will receive points for each JUnit test you pass. Code style will not be graded. The class should have exactly one field (the HashMap) and the following seven methods:
/**
* Initialize an empty bag with an initial capacity of 10.
* @postcondition
* This bag is empty and has an initial capacity of 10.
**/
public BagOfWords()
{
}
/**
* Initialize an empty bag with a specified initial capacity.
* @param initialCapacity
* the initial capacity of this bag
* @precondition
* initialCapacity is non-negative.
* @postcondition
* This bag is empty and has the given initial capacity.
**/
public BagOfWords(int initialCapacity)
{
}
/**
* Add a new element to this bag.
* @param word
* the new word that is being inserted
* @postcondition
* A new copy of the word has been added to this bag.
**/
public void add(String word)
{
}
/**
* Accessor method to count the number of occurrences of a particular
* element in this bag.
* @param word
* the word that needs to be counted
* @return
* the number of times that word occurs in this bag
**/
public int countOccurrences(String word)
{
return -1;
}
/**
* Remove one copy of a specified word from this bag.
* @param word
* the word to remove from the bag
* @postcondition
* If the word was found in the bag, then one copy of
* the word has been removed and the method returns true.
* Otherwise the bag remains unchanged and the method returns false.
* @return true if the word was successfully removed.
**/
public boolean remove(String word)
{
return false;
}
/**
* Determine the number of words in this bag.
* @return
* the number of words in this bag
**/
public int size()
{
return -1;
}
/**
* Produce one long string from the values in the BagOfWords.
* If a string appears more than one time in the bag, it should
* appear more than once in the output. Do not insert spaces.
* @return the long string
*/
public String oneLongString()
{
return null;
}
This is in Java
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch