Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 17, Problem 5PC
Program Plan Intro

ObjectBinarySearcher class

Program plan:

  • Create the class “ObjectBinarySearcher”,
    • Define the generic method “search()” that implement “Comparable” interface.
    • Declare the required variables.
    • Use the while loop to check whether the searching value is found in the array or searching reaches the end of an array.
      • Calculate the “middle” value.
    • Check whether the “middle” value is at index “0”. If yes, then set the boolean value for “found” to be “true”.
      • Assign the “middle” value index to “position” variable.
    • Check whether the searching value when compared to “middle” is greater than 0.
      • If yes, search the left half of the array otherwise search the right half of the array.
    • Return the position of the element.
  • Create the class “ObjectBinarySearchTest”,
    • Define the “main()” function,
      • Assign the string values.
      • Read the input from the user through “Scanner” to search the value in the array.
      • Execute “do…while” loop to search the value in an array until it iterates all the elements in an array.
      • Call the “search()” method to find the searching element in the array.
      • If the searching value is found, then print the corresponding message otherwise print the message as “element is not found in the array”.
      • If the user needs to continue search some other element then press “Y”, or “y” to continue and “N”, or “n” to exit the program.

Blurred answer
Students have asked these similar questions
Create a SameItem Interface: The SameItem interface will be a generic interface.SameItem will have a single method: isSameAs(T) that returns a boolean
Dynamic Apex: Write test class for this apex code(Not required the output) You are working on the project in which you have to create the apex code in which your task is to define the objects dynamically by using the method argument which is api name in string and a map of string, string as a key value pair. Class Code: public static void modifySobjectData(String str , Map mapofString) { //Retrive the type of Sobject by using the getGlobalDescribe Schema.SobjectType targetType = Schema.getGlobalDescribe().get(str); //Initalize the Object Sobject newobject = targetType.newSobject(); for(String s :mapofString.keySet(O) { newobject.put(s, mapofString.get(s)); } System.debug('newObject' + newobject); //Perform the DML if(targetType != null) insert newobject; } }
Java Objects and Linked Data: Select all of the following statements that are true. The Java Class Library's class ArrayList implements the LinkedList interface. In Java, when one reference variable is assigned to another reference variable, both references then refer to the same object. In Java, the "equals"-method that any object inherits can be overwritten to compare objects field by field.

Chapter 17 Solutions

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Ch. 17.3 - Prob. 17.11CPCh. 17.3 - Prob. 17.12CPCh. 17.3 - Prob. 17.13CPCh. 17.3 - Prob. 17.14CPCh. 17.4 - Prob. 17.15CPCh. 17.5 - Prob. 17.16CPCh. 17.5 - Prob. 17.17CPCh. 17.6 - Prob. 17.18CPCh. 17.6 - Prob. 17.19CPCh. 17.6 - Prob. 17.20CPCh. 17.8 - Prob. 17.21CPCh. 17.8 - Prob. 17.22CPCh. 17.9 - Prob. 17.23CPCh. 17.9 - During the process of erasure, when the compiler...Ch. 17.9 - Prob. 17.25CPCh. 17 - Prob. 1MCCh. 17 - Prob. 2MCCh. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Prob. 7MCCh. 17 - Prob. 8MCCh. 17 - Prob. 9MCCh. 17 - The process used by the Java compiler to remove...Ch. 17 - True or False: It is better to discover an error...Ch. 17 - Prob. 12TFCh. 17 - True or False: Type parameters must be single...Ch. 17 - Prob. 14TFCh. 17 - Prob. 15TFCh. 17 - True or False: You cannot create an array of...Ch. 17 - Prob. 17TFCh. 17 - Prob. 18TFCh. 17 - Prob. 1FTECh. 17 - Assume the following is a method header in a...Ch. 17 - public class MyClassT { public static void...Ch. 17 - public class PointT extends Number super Integer {...Ch. 17 - Assume there is a class named Customer. Write a...Ch. 17 - Assume names references an object of the...Ch. 17 - Prob. 3AWCh. 17 - Prob. 4AWCh. 17 - Prob. 5AWCh. 17 - Prob. 6AWCh. 17 - Prob. 7AWCh. 17 - Prob. 1SACh. 17 - Look at the following method header: public T...Ch. 17 - Prob. 3SACh. 17 - Do generic types exist at the bytecode level?Ch. 17 - Prob. 5SACh. 17 - When the compiler encounters a class, interface,...Ch. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PC
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education