Double division behaving wrongly
Solution 1:
You're performing an integer division and then type casting:
tf = (double) ( word.getValue() / noOfTerms );
^-----integer division----^
Type cast one of the elements in the division to convert into a floating point division:
tf = ((double)word.getValue()) / noOfTerms;
Solution 2:
You are doing integer division and then casting that answer to a double. What you need to do is cast one of the two values to a double first, and then do division on it. That should get you the answer you desire.