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 data; public ListOfFrequency(){ data = new ArrayList(); } public void add(Frequency obj){ data.add(obj); } public String toString(){ int i; String str; if ( data.size() == 0 ){ return "[]"; } else{ str = "["; for(i=0; i

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:

 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 ); } 

The above, compiled and run, should produce:

> run Utilities [(mango, 2), (apple, 3), (banana, 1)] > 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!