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 03:00
Why were the farmers not satisfied with only establishing cooperatives ?
Answers: 1
question
Advanced Placement (AP), 23.06.2019 12:50
Free points + brainliest ! only for correct answer when a vehicle is in motion, it has a. no weight b. no inertia c. potential energy d. kinetic energy
Answers: 2
question
Advanced Placement (AP), 25.06.2019 19:30
In 2009, roughly of people age 12 or older who did not drink alcohol were current users of illegal drugs. a. 4% b. 10% c. 13% d. 20%
Answers: 1
question
Advanced Placement (AP), 27.06.2019 05:00
Most four year colleges look at all the following statistics on a students application except a: standardizes test scores b: iq c: gpa d: class rank
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, 21.10.2020 20:01
question
Mathematics, 21.10.2020 20:01
question
Mathematics, 21.10.2020 20:01
question
Computers and Technology, 21.10.2020 20:01
question
Mathematics, 21.10.2020 20:01
Questions on the website: 13722362