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), 24.06.2019 03:30
Luke finds a great deal for pudding cups on amazon. he can get a 36 pack for $9.74. what a deal! each cup holds 3.25oz of yummy pudding, btw. luke also knows that the hot tub is about 5 feet width, 5 feet long, and 2.5 feet deep. how many packs will luke need to buy in order to fill the hot tub? how much will this prank cost him? need
Answers: 1
question
Advanced Placement (AP), 26.06.2019 04:00
What information does a survey provide? a. an accurate description of the population surveyed b. whether there is a predictive relationship between two variables? c. whether there is a cause-and-effect relationship between two variables d. none
Answers: 2
question
Advanced Placement (AP), 26.06.2019 08:50
1. the community center is putting on a play. there are several things the crew has to create for the scenery. (a) they spent $6.17 on each of 4 poster boards. how much did they spend on poster boards in total? show your work. (b) they spent $200.20 total on new lighting. each of the four lights cost the same amount. how much did they pay per light? show your work. (c) if the total budget was $300, how much more can they spend? show your work.
Answers: 2
question
Advanced Placement (AP), 26.06.2019 13:50
Which of the following activities would conserve the most energy? installing a dimmer switch on a light using a blender instead of a food processor hanging clothes to dry on a clothesline instead of ironing them opening a window instead of turning on the air conditioning setting your computer's screen saver to turn on after less time has elapsed
Answers: 1
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