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

The IntBinarySearcher class presented in this chapter searches an int array for

ID: 3652028 • Letter: T

Question

The IntBinarySearcher class presented in this chapter searches an int array for a specific value. Create an ObjectBinarySearcher class that can search an array of Comparable objects. Demonstrate the class in a program that searches for a String in an array of String objects.

From Starting Out With Java From Control Structures through Data Structures, 2nd Edition by Tony Gaddis

IntBinarySearcher can be found here: http://www.cs.albany.edu/~sdc/CSI201/Fal10/Classes/C37/Source Code/Chapter 16/IntBinarySearcher.java

Explanation / Answer

//ObjectBinarySearcher class public class ObjectBinarySearcher { public static int search(Object[] array, Object value) { int first; int last; int middle; int position; boolean found; first = 0; last = array.length - 1; position = -1; found = false; while (!found && first 0) last = middle - 1; else first = middle + 1; } return position; } } //test program public class testObjectBinarySearcher { public static void main(String args[]) { String[] s = new String[5]; s[0]=new String("alpha"); s[1]=new String("beta"); s[2]=new String("delta"); s[3]=new String("gamma"); s[4]=new String("xilinx"); ObjectBinarySearcher o = new ObjectBinarySearcher(); System.out.println(o.search(s,"beta")); } }
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