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
Functions with 2D Arrays in Java Write a function named displayElements that takes a two-dimensional array, the size of its rows and columns, then prints every element of a two-dimensional array. Separate every row by a new line and every column by a space.   In the main function, call the displayElements function and pass in the required parameters.   Output 1 2 3 4 5 6 7 8 9
JAVA PLEASE FAAST Write a java method that receives a string containing letters of the English alphabet and then prints the  Letters whose frequencies are not unique. Notes:  1) Ignore letter case; Uppercase and lowercase letters are considered the same.  2) Do not use methods from the Arrays class.
Using jGRASP please de-bug this /**This program demonstrates an array of String objects.It should print out the days and the number of hours spent at work each day.It should print out the day of the week with the most hours workedIt should print out the average number of hours worked each dayThis is what should display when the program runs as it shouldSunday has 12 hours worked.Monday has 9 hours worked.Tuesday has 8 hours worked.Wednesday has 13 hours worked.Thursday has 6 hours worked.Friday has 4 hours worked.Saturday has 0 hours worked.Highest Day is Wednesday with 13 hours workedAverage hours worked in the week is 7.43 hours*/{public class WorkDays{public static void main(String[] args){String[] days = { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"}; int[] hours = { 12, 9, 8, 13, 6, 4}; int average = 0.0;int highest = 0;String highestDay = " ";int sum = 0; for (int index = 0; index < days.length; index++){System.out.println(days[index] + " has "…

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
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,