Menu

Define a method named getWordFrequency that takes an array of strings, the size of the array, and a search word as parameters. Method getWordFrequency() then returns the number of occurrences of the s…

Question

Answered step-by-step

Define a method named getWordFrequency that takes an array of…

Define a method named getWordFrequency that takes an array of strings, the size of the array, and a search word as parameters. Method getWordFrequency() then returns the number of occurrences of the search word in the array parameter (case insensitive).

Then, make a main program that reads a list of words into an array, calls method getWordFrequency() repeatedly, and outputs the words in the arrays with their frequencies. The input begins with an integer indicating the number of words that follow. Assume that the list will always contain less than twenty words.

Ex: If the input is:

5 hey Hi Mark hi mark

the output is:

hey 1 
Hi 2 
Mark 2 
hi 2 
mark 2

Hint: Use the equalsIgnoreCase() method for comparing strings, ignoring case.

The program must define and call a method:
public static int getWordFrequency(String[] wordsList, int listSize, String currWord)

 

Given Code:

import java.util.Scanner;

public class LabProgram {

   /* Define your method here */

   public static void main(String[] args) {
      /* Put your code here. */
   }
}

OR

Leave a Reply

Your email address will not be published. Required fields are marked *