subject

Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.
Some applications use a controlled vocabulary to describe, or tag, things. A controlled vocabulary is a limited set of keywords from which appropriate tags can be chosen.
The Vocab class, shown below, contains methods used to analyze words in terms of their presence in a controlled vocabulary. You will write two methods of the Vocab class.
public class Vocab
{
/** The controlled vocabulary for a Vocab object. */
private String[] theVocab = { /* contents not shown */ };
/** Searches for a string in theVocab. Returns true if its String parameter str
* is an exact match to an element in theVocab and returns false otherwise.
*/
public boolean findWord(String str)
{
/* implementation not shown */
}
/** Counts how many strings in wordArray are not found in theVocab, as described in
* part (a).
*/
public int countNotInVocab(String[] wordArray)
{
/* to be implemented in part (a) */
}
/** Returns an array containing strings from wordArray not found in theVocab,
* as described in part (b).
*/
public String[] notInVocab(String[] wordArray)
{
/* to be implemented in part (b) */
}
}
The countNotInVocab method returns an int that contains the number of words in its parameter wordArray that are not found in the instance variable theVocab.
A helper method, findWord, has been provided. The findWord method searches for an individual string in theVocab, returning true if an exact match between its String parameter and an element of theVocab is found, and returning false otherwise.
(a) Write the countNotInVocab method. Assume that there are no duplicates in wordArray. You must use findWord appropriately to receive full credit.
/** Counts how many strings in wordArray are not found in theVocab, as described in
* part (a).
*/
public int countNotInVocab(String[] wordArray)
The notInVocab method returns an array of String objects that contains only elements of its parameter wordArray that are not found in theVocab. The array that is returned by notInVocab should have exactly one element for each word in wordArray that is not found in theVocab. Assume that there are no duplicates in wordArray.
The following example illustrates the behavior of the notInVocab method.
theVocab:
"time""food""dogs""cats""health""pl ants""sports"
wordArray:
"dogs""toys""sun""plants""time"
Array returned by notInVocab:
"toys""sun"
(b) 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)

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:00
Aplan to budget time for studying and activities is referred to as a study routine. study habits. study skills. a study schedule.
Answers: 1
question
Computers and Technology, 23.06.2019 11:00
In the context of the box model, what is the difference between a margin and a padding? a. a padding lies outside a box border, while a margin lies inside it. b. a padding lies inside a box border, while a margin lies outside it. c. a padding can be adjusted independently, while a margin depends on the size of its box. d. a padding depends on the size of its box, while a margin can be adjusted independently.
Answers: 3
question
Computers and Technology, 23.06.2019 17:00
What does the faves button do? a. users mark a web page as a favorite b. leads other readers to favor a specific page c. readers sort and align their favicons, or favorite icons d. leads users to a message board where they can post questions
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
Write a program that displays the following menu: geometry calculator 1. calculate the area of a circle 2. calculate the area of a rectangle 3. calculate the area of a triangle 4. quit enter your choice (1-4): if the user enters 1, the program should ask for the radius of the circle and then display its area. use the following formula: area = ď€(the square of r) use 3.14159 for ď€ and the radius of the circle for r. if the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle’s area. use the following formula: area = length * width if the user enters 3, the program should ask for the length of the triangle’s base and its height, and then display its area. use the following formula: area = base * height * .5 if the user enters 4, the program should end. input validation: display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. do not accept negative values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height. note: if the user enters an improper menu choice (1-4), the program prints "the valid choices are 1 through 4. run the program again and select one of those." if the user enters a negative radius, the program prints "the radius can not be less than zero." if the user enters a negative value for height or base, the program prints "only enter positive values for base and height."
Answers: 1
You know the right answer?
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Un...
Questions
question
Mathematics, 05.05.2020 09:49
Questions on the website: 13722359