115k views
2 votes
Write the notInVocab method. Assume that there are no duplicates in wordArray. You must call findWord and countNotInVocab appropriately in order to receive full credit. /** Returns an array containing strings from wordArray not found in theVocab, * as described in part (b). */ public String[] notInVocab(String[] wordArray)

User Aleien
by
5.1k points

2 Answers

3 votes

Final answer:

The notInVocab method is used to return an array of strings from wordArray that are not found in theVocab. It calls the findWord and countNotInVocab methods to achieve this.

Step-by-step explanation:

The notInVocab method is used to return an array containing strings from wordArray that are not found in theVocab. To implement this method, you need to call the findWord and countNotInVocab methods appropriately. Here is an example implementation:

public String[] notInVocab(String[] wordArray) {
int count = countNotInVocab(wordArray);
String[] notInVocabArray = new String[count];
int index = 0;
for (int i = 0; i < wordArray.length; i++) {
if (!findWord(wordArray[i], theVocab)) {
notInVocabArray[index] = wordArray[i];
index++;
}
}
return notInVocabArray;
}
User LBF
by
5.3k points
2 votes

Final answer:

The notInVocab method is a Java method that takes an array of strings called wordArray as input and returns an array containing the strings from wordArray that are not found in theVocab. It can be implemented by calling the findWord method and the countNotInVocab method appropriately.

Step-by-step explanation:

The notInVocab method is a Java method that takes an array of strings called wordArray as input and returns an array containing the strings from wordArray that are not found in theVocab. To implement this method, you would need to call the findWord method and the countNotInVocab method appropriately.

Here's an example implementation:

public String[] notInVocab(String[] wordArray) {
ArrayList notInVocabList = new ArrayList<>();
for (String word : wordArray) {
if (!findWord(word)) {
notInVocabList.add(word);
}
}
return notInVocabList.toArray(new String[0]);
}

In this implementation, the findWord method is used to check if a word is found in theVocab. If a word is not found, it is added to the notInVocabList. Finally, the notInVocabList is converted to an array and returned as the result.

User Carlos Negron
by
4.2k points