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 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) LAB ACTIVITY 8.45.1: LAB: Word frequencies - methods 0 / 10 LabProgram.java Load default template... Слд 1 import java.util.Scanner; 2 3 public class LabProgram { 4 5 /* Define your method here */ 6 7 public static void main(String[] args) { 8 /* Type your code here. */ 9 } 10 } 11 NO

Respuesta :

Using the knowledge in computational language in JAVA it is possible to write the code being methods define a method named getWordFrequency that takes an array of strings

Writting the code in JAVA:

import java.util.*;

public class WordFrequency {

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

               HashMap<String , Integer> hm = new HashMap<>();

               for(String st : wordsList) {

                       String str = st.toLowerCase();

                       hm.put(str, hm.getOrDefault(str, 0) + 1);

               }

               for(String st : wordsList) {

                       String str = st.toLowerCase();

                       System.out.println(st + " " + hm.get(str));

               }

               String currWordToLowerCase = currWord.toLowerCase();

               return hm.get(currWordToLowerCase);

       }

       public static void main(String[] args) {

               // TODO Auto-generated method stub

               String[] wordsList = {"hey" , "Hi" , "Mark" , "hi" , "mark"};

               int listSize = wordsList.length;

               String currWord = "hey";

               System.out.println("The frequency of " + currWord + " is : " + getWordFrequency(wordsList , listSize , currWord));

       }

}

See more about JAVA at brainly.com/question/12978370

#SPJ1

Ver imagen lhmarianateixeira