Question: Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Notes: Assume that the classes listed in the Java Quick

Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.

Notes:

  • 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 notnulland 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.

2. This question involves analyzing integer values that are obtained using thegetIntmethod in the followingIntegerAnalysisclass. You will write one method in the class.

public class IntegerAnalysis

{

/**Returns anintfrom simulated user input*/

public static int getInt()

{/*implementation not shown*/}

/**Analyzesnvalues obtained from thegetIntmethod and returns the proportion

*of these values that meet the criteria described in part (a)

*Precondition:max > 0,n > 0

*/

public static double analyzeInts(int max, int n)

{/*to be implemented in part (a)*/}

//There may be variables and methods that are not shown.

}

(a) Write methodanalyzeInts,which obtainsnvalues using thegetIntmethod and returns the proportion of the obtained values that meet all the following criteria.

  • The value is greater than0
  • The value is less thanmax
  • The value is divisible by3

For example, ifmaxis10and the values obtained bygetIntare6,-3,5,0,12,3,3,and9,thenanalyzeIntsshould return0.5because four of the eight values(6,3,3,and9)meet all the criteria.

Complete methodanalyzeInts.

/**Analyzesnvalues obtained from thegetIntmethod and returns the proportion of

*these values that meet the criteria described in part (a)

*Precondition:max > 0,n > 0

*/

public static double analyzeInts(int max, int n)

(b) A programmer wants to modify theIntegerAnalysisclass so that in theanalyzeIntsmethod, the check for divisibility by an integer can vary between method calls. For example, in one call toanalyzeInts,the method might check for divisibility by3,and in another call toanalyzeInts,the method might check for divisibility by10.The programmer wants to implement this change without making any changes to the signature of theanalyzeIntsmethod or overloadinganalyzeInts.

Explain how you would change theIntegerAnalysisclass 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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!