Question: Java import java.util.*; public class ListOfFrequency{ private ArrayList data; public ListOfFrequency(){ data = new ArrayList (); } public void add(Frequency obj){ data.add(obj); } public String
Java
import java.util.*; public class ListOfFrequency{ private ArrayList Design a function count-word which consumes a ListOfFrequency and a String. It adds 1 to the frequency for that string, producing a new ListOfFrequency. If there is no Frequency for that string, the resulting ListOfFrequency grows, as follows. It adds, as a result of running count-word, a new Frequency with that string and the number 1. Here's how it might work: The above, compiled and run, should produce: public static void main(String[] args) { ListOfFrequency lof = new ListOfFrequency(); Utilities.countWord( lof, "mango" ); Utilities.countWord( lof, "apple" ); Utilities.countWord( lof, "banana" ); Utilities.countWord( lof, "mango" ); Utilities.countWord( lof, "apple" ); Utilities.countWord( lof, "apple" ); System.out.println( lof ); } > run Utilities [(mango, 2), (apple, 3), (banana, 1)] >
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
