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 16, Problem 3PC
Program Plan Intro

Searching for Objects with the Binary search Algorithm

Program plan:

  • Create the class “ObjectBinarySearcher”,
    • Define the “search()” method,
    • Declare the required variables.
    • Use the while loop to check whether the searching value is found in the array or searching reaches end of the 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.
      • Call the “quicksort()” method to sort the values.
      • Execute the do…while loop to search the value in the array until it iterates all the elements in the 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 “element not found in the array”.
      • If the user needs to continue the choice to search the element. Press yes or “y” to continue otherwise exit the program.

Blurred answer
Students have asked these similar questions
Recipe Program - Java ONLYI am looking to create a program that is a recipe holder. It needs to include at a minimum: At least 1 loop An Array or ArrayList At least 3 Java classes Use of methods The program would allow the user to (as part of a menu selection): Add a recipe Include ingredient list Instructions List all recipes that are in the program (array) Display a single recipe Search Recipes (option to view recipe selected) For example, searching for peanut butter cookie would bring up the recipe or multiple if the same name. The user could then select one of them to view the recipe. Search Recipes with a single ingredient (option to view recipe selected) For example: search for coconut and it would bring up coconut cream pie and German chocolate cake. The user could then select one of them to view the recipe. Close application Also need the program in a UML diagram.
20- $footboll=array(); is an example of: a. boolean b. None c. function d. empty array
17. Phone Book ArrayList Write a class named PhoneBookEntry that has fields for a person's name and phone number. The class should have a constructor and appropriate accessor and mutator methods. Then write a program that creates at least five PhoneBookEntry objects and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList.

Chapter 16 Solutions

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

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
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,