Please write a program that performs a binary search on a sorted array.
Write the interface SortedList with the following methods:
//write a binary search for Strings, remember String implements Comparable automatically so you have access
//to String’s compareTo() method. Look it up to see how it works.
public int binarySearch(String words, String key, int size);
//adds the value at an index that maintains sorted order, and not necessarily at the end
//increase the number of toppings by 1, Find the position where top goes and move the others down and insert
//the correct topping.
public boolean add(String top);
obj.add(“pineapple”) would yield true and
once you have 20 toppings the add method would return
false and print the message “no more toppings”
//searches for the correct topping, then deletes it and maintains sorted order
// Find the position where the topping goes and move the others down
// decrease the number of toppings by 1
public boolean delete(String top);
obj.delete(“ham”) would yield true and
once you have 0 toppings the delete method would return
false and print the message “no toppings”
//prints a numbered list going down.
// Note the numbers are one more than the index
public String printArray();
Here are the toppings:
2. extra cheese
3. ground beef
Write class called MyList that implements the SortedList interface.
You will need one instance variable that is a String Array that could hold
up to 20 toppings and an integer with how many are valid toppings
Originally the integer should have the value 9. You will need
one constructor without parameters that creates the list of the 9 given
pizza toppings. Toppings 10-20 should be “ZZZ”.
Write the add method that will insert a topping in the correct place in the
list. You need to find the correct place in the array, bump the current values down and then insert the new topping.
Write the delete method that will delete a topping from the correct place in the list. You need to find the correct place in the array and bump the current values up.
Add the methods to get the instance variables and the printArray()method. Only print the toppings that are valid.
You do not need the set methods.
Write a that MyListTester that
1. Creates a list of pizza toppings.
2. Print out the list.
3. Add three more toppings to the list.
4. Print out the list
5. Delete two toppings from the list.
6. Print out the list
7. Ask the person to pick a topping and call the binary search method to decide if the topping is there.
8. Do this 4 times with some toppings being there and some not.
DO NOT USE THE JAVA BUILT IN SEARCH OR SORT.