Could youy please explain th code if possible Please and Thank you Ask if you need anything.
Question:
Could youy please explain th code if possible
Please and Thank you
Ask if you need anything.
Watch:
https://youtu.be/RWA_0-iPLGw
https://youtu.be/On4qmiBgrbI
https://youtu.be/wGKXS5_PtcI
Iterative Algorithms Assignment 1: Binary Search (Searching Numbers)
You need to design and use two Binary Search methods each of which will be quite similar.
Make a new Java Main Class called BinarySearch_Numbers_LastName.java.
Part A - Integer Binary Search (30%)
1.Make an integer array containing the following exact numbers in order.
12, 13, 32, 35, 46, 68, 71, 73, 88, 94, 99, 100
2.You should already have a BinarySearch method for searching Integer Arrays from the CodeHS lessons. Copy it below your main method.
public int binarySearch(int[] array, int key)
{
int low = 0;
int high = array.length - 1;
while(low <= high)
{
int mid = (low + high) / 2;
int cur = array[mid];
if(cur == key)
{
return mid;
}
else if(cur < key)
{
low = mid + 1;
}
else
{
high = mid - 1;
}
}
return -1;
}
3.Proofread your list. Remember that your list must be in numerical order for a binary search to work.
4. Ask the user to enter a number.
5.Call the Binary Search method to return the index number.
1.If the number is found, say "I found it at index number __. ".
2.If it is not found, say "I am sorry this number is not in our list. Please try again". These printouts should happen in main(). Do NOT alter the basic search methods.
Part B - Overload the method to use doubles.(60%)
1.Recreate the binary search method to receive an array of doubles.
Remember that this copy can be named exactly the same as the original due to a concept called "overloading".
2.Make an array of 10 names of superheroes/cartoon characters/apple varieties/whatever. (You can be creative about the subject matter of this part of the program, especially if you are tired of superheroes. However, make sure you read over the rest of the assignment to make sure you are still creating code with identical capabilities.)
3.Make an array of 10 doubles where their Power/Flavour/whatever Levels are measured from 0 to 0.99
- Remember that they must be from lowest to highest.
- Each power level must be unique.
4.Ask the user to enter a Power Level.
5.Search the Power Level Array and save the index value it finds back in main. (In other words, call the BinarySearch method to return the index number.)
6.Using the index value back in main:
- If the number is found, use it to look up the hero's name. Then say "You have chosen hero _____ to be your sidekick.
"
- If it is not found, say "I am sorry this number is not in our list. ".
- These printouts should happen in main().