public class FrequencyDictionaryImp extends DictionaryImp implements Dictionary { //Data private boolean created; private int count; //Constructor public FrequencyDictionaryImp(Function table) { super(table); created = false; count = 0; } //Public method public FrequencyDictionaryImp create() { java.util.Iterator it = super.keys(); while (it.hasNext()) { String word = (String)(it.next()); Object value = get(word); double frequency = ((Double)value).doubleValue() / count; super.put(word,(new Double(frequency))); } created = true; return this; } //Dictionary methods - inherited from DictionaryImp //Override method public Object put(String word,Object value) { if(created) throw new UnsupportedOperationException("Dictionary is created!"); Double valueNew = ((Double)value); count += valueNew; Object valueOld = super.get(word); if(valueOld != null) valueNew = new Double(((Double)valueOld).doubleValue() + ((Double)valueNew).doubleValue()); super.put(word,valueNew); return valueNew; } }