LAB: Word frequencies - methods 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, write 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 20 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 equalslgnoreCase() method for comparing strings, ignoring case. Hint: Use the equalslgnoreCase() method for comparing strings, ignoring case. The program must define and call a method: public static int getWordFrequency(String[] wordsList, int listSize, String currWord).

Respuesta :

The program is an illustration of loops, functions and conditional statements

  • Loops are used for repetition
  • Functions are used to group related code statements in a block
  • Conditional statements are used to make decisions

The program in Java

The program written in Java, is as follows:

import java.util.Scanner;

public class Main {

   public static int getFrequencyOfWord(String[] wordsList, int listSize, String currWord) {

       int wordFreq = 0;

       for (int i=0; i<listSize; i++){

           if (wordsList[i].compareToIgnoreCase(currWord)==0){

               wordFreq++;

           }

       }

       return wordFreq;

   }

       public static void main(String[] args) {

           Scanner input = new Scanner(System.in);

           int N = input.nextInt();

           String myArr[] = new String[N];

           for (int i=0; i<N; i++){

               myArr[i] = input.next();

           }

           for (int i=0; i<N; i++){      

               String searchWord = myArr[i];

               int freqCount = getFrequencyOfWord(myArr,N,searchWord);

               System.out.println(searchWord + " " + freqCount);

       }              

  }

}

Read more about java programs at:

https://brainly.com/question/26642771

#SPJ1