Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the definition shown below for the \"jumpSearch\" method of the SkipSearch c

ID: 3728782 • Letter: U

Question

 Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that the method is delcared static. Therefore, you do not need to create a new  instance of the object before the method is called. Simply use "SkipSearch.jumpSearch(...)" with the appropriate 4 parameter values.  When objects are compared, you should use the "compareTo" method as in the following example.   item.compareTo(array[k])   However, not every type of object implements the compareTo method of the Comparable interface. This is resolved with the use of the syntax " T extends Comparable<? super T>" where "T" represents the type of objects you want to compare. On the other hand, if you only need to use one type of data object, then you could just define your data class to implement Comparable instead.  public class SkipSearch {     public static <T extends Comparable<? super T>>                       boolean jumpSearch( T[] array, int size, T item, int skip )      {         /*  Searches the first n objects in a sorted array for a given item.         T      -  data type or class name for the objects in the array.         array  -  An array of Comparable objects sorted into ascending order.         size   -  Array size.         item   -  The item sought.         skip   -  An integer > 0; The gap between examined items.         returns  true if the item was found, or false if not. */           // Insert your code here. Also define the main test class in a separate Java file.      } } 

Explanation / Answer

public class SkipSearch

{

   public static <T extends Comparable<? super T>>

   boolean jumpSearch( T[] array, int size, T item, int skip )

   {

       /* Searches the first n objects in a sorted array for a given item.

T - data type or class name for the objects in the array.

array - An array of Comparable objects sorted into ascending order.

size - Array size.

item - The item sought.

skip - An integer > 0; The gap between examined items.

returns true if the item was found, or false if not. */

       // Insert your code here. Also define the main test class in a separate Java file.

      

       for(int i=0; i<size; i=i+skip) {

           if(array[i].compareTo(item) == 0)

               return true;

       }

      

       return false;

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote