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

Other questions on the subject: Advanced Placement (AP)

image
Advanced Placement (AP), 22.06.2019 07:30, AmyGonzalez1385
Southern tick-associated rash illness (stari) is a disease often carried by deer ticks in the southern united states. which sentence best explains how climate change could increase the number of stari cases? a. infectious diseases may become more widespread as ticks increase their range. b. ticks may weaken the animals they feed on, causing more deaths in the population. c. people who work in agriculture may have to relocate to find new employment. d. rising seas and flooding may result in the displacement of millions of people.
Answers: 1
image
Advanced Placement (AP), 25.06.2019 15:50, AmyGonzalez1385
This is an ap world history question. i am working on a worksheet which has a vent diagram with each circle labeled either us or byzantine economy. the middle is the similarities. can someone explain to me the similarities and especially the differences between the two?
Answers: 3
image
Advanced Placement (AP), 25.06.2019 19:00, KindaSmartPersonn
Environmental science jobs are expected to grow by how much between now and 2016? a) 5% b) 15% c) 25% d) 100%
Answers: 1
image
Advanced Placement (AP), 25.06.2019 23:00, andrejr0330jr
For which plan or plans. is knowing the withdrawal restrictions important ?
Answers: 3
You know the right answer?
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Un...

Questions in other subjects:

Konu
Physics, 23.06.2019 18:30