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.

4. This question involves analyzing numbers that are obtained using the getNumber method in the following NumberChecker class. You will write one method in the class.

public class NumberChecker
{
/** Returns an int value to be analyzed */
public static int getNumber()
{ /* implementation not shown */ }

/** Returns true if x is a target number and returns false otherwise */
public static boolean isTarget(int x)
{ /* implementation not shown */ }

/** Analyzes values obtained using the getNumber method, as described in part (a)
* Precondition: 0 < n < max
*/
public static int countNumbers(int n, int max)
{ /* to be implemented in part (a) */ }

// There may be variables and methods that are not shown.
}
(a) Write method countNumbers, which obtains values using the getNumber method and returns the number of calls to getNumber that are made until n values are obtained that meet both of the following criteria.

Is NOT a target number, as determined by the isTarget method
Is divisible by 3
If max calls are made to getNumber without obtaining n values that meet the criteria, -1 is returned.

A helper method, isTarget, has been provided. The method returns true if its integer parameter is a target number and returns false otherwise. You must use isTarget appropriately to receive full credit.

Complete method countNumbers.

/** Analyzes values obtained using the getNumber method, as described in part (a)
* Precondition: 0 < n < max
*/
public static int countNumbers(int n, int max)

Question 2
(b) A programmer wants to modify the NumberChecker class so that in the countNumbers method, the check for divisibility by an integer can vary between method calls. For example, in one call to countNumbers, the method might check for divisibility by 3, and in another call to countNumbers, the method might check for divisibility by 2.

The programmer would like to implement this change without making any changes to the signature of the countNumbers method or overloading countNumbers.

Write a description of how you would change the NumberChecker class in order to support this modification. Do not write the program code for this change.

Make sure to include the following in your response.

Identify any new or modified variables or methods.
Describe, for each new or revised variable or method, how it would change or be implemented, including visibility and type.

ansver
Answers: 2

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 23.06.2019 19:30
Describe alvord's tone in the two paragraphs on the history of dartmouth and its native american studies program (paras. 21-22)?
Answers: 3
question
Advanced Placement (AP), 24.06.2019 15:00
What best describes the portability characteristic of money?
Answers: 1
question
Advanced Placement (AP), 25.06.2019 21:30
If you have a green turn signal light, you must before making your turn. a. check the crosswalk b. yield to cross traffic and check the crosswalk c. turn off your car's turn signal d. none of the above
Answers: 2
question
Advanced Placement (AP), 26.06.2019 22:30
What member of staff does a patient see to have her teeth cleaned
Answers: 2
You know the right answer?
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Un...
Questions
Questions on the website: 13722360