Home / Expert Answers / Computer Science / use-java-use-java-working-on-this-public-class-stringops-int-counts-pa541

(Solved): USE JAVA Use java working on this: public class StringOps { int counts; /** ...



USE JAVA

Implementing StringOps
Your Stringops class should contain four methods:
1. pub1ic int 1inearSearch(String [] array, String q

Use java working on this:

public class StringOps {
    int counts;

    /**
     * _Part 1: Implement this method._
     *
     * Approach:
     * Walk through the specified String array from the index l,
     * upto, but not including the index r
     *
     * @param array - the array of Strings to search
     * @param query - a String to search for in 'array'
     * @param l     - the first index of the search range
     * @param r     - the end (exclusive) of the search range
     * @return the index of the query in the array or -1 if not found.
     */
    public int linearSearch(String[] array, String query, int l, int r) {
        // TODO: implement this
        return 0;
    }

    /**
     * _Part 2: Implement this method._
     *
     * Approach:
     * Perform binary search on the specified String array between the index l,
     * upto, but not including the index r
     *
     * @param sortedArray - the array of Strings to search
     * @param query       - a String to search for in 'array'
     * @param l           - the first index of the search range
     * @param r           - the end (exclusive) of the search range
     * @return the index of the query in the array or -1 if not found.
     */
    public int binarySearch(String[] sortedArray, String query, int l, int r) {
        // TODO: implement this
        return 0;
    }

    /**
     * _Part 3: Implement this method._
     *
     * Approach:
     * Sort the array in-place.
     * Walk over the array, if a pair of items is "out of order",
     * swap the items. If any pair was swapped, repeat the walk.
     *
     * @param array - the array of Strings to sort
     */
    public void swapemSort(String[] array) {
        // TODO: implement this
        return;
    }

    /**
     * _Part 4: Implement this method._
     *
     * Approach:
     * Sort the array in-place using 'insertion sort'.
     *
     * @param array - the array of Strings to sort
     */
    public void insertSort(String[] array) {
        // TODO: implement this
        return;
    }

    /**
     * _ Part 5: Implement this method _
     *
     * Approach:
     * Do this in two stages.
     *
     * For the first stage, create an array big enough to hold all
     * items in both array1 and array2, and fill it with unique items
     * from array1 and array2.
     *
     * For the second stage, create an array just big enough for the
     * unique items and copy them from the array created in the previous
     * step
     *
     * Hint: should you generally use equals() or == with Strings?
     *
     * NOTE:
     * You should only use String arrays and primitive types
     * for your implementation.
     *
     * @param array1 - the first array of Strings
     * @param array2 - the second array of Strings
     * @return a new array holding all unique items in array1 and array2
     */
    public String[] union(String[] array1, String[] array2) {
        // TODO: implement this
        return null;
    }

    /**
     * _ Part 6: Implement this method _
     *
     * Approach:
     * Do this in two stages.
     *
     * For the first stage, create an array big enough to hold all
     * items in the smaller of array1 or array2, and fill it items that
     * occur in both arrays. However, the resulting array should be
     * a set (only contain unique items) even if array1 or array2 is
     * not a set.
     *
     * For the second stage, create an array just big enough for the
     * items above and copy them from the array created in the previous
     * step
     *
     * Hint: should you generally use equals() or == with Strings?
     * Hint: use Math.min
     *
     * NOTE:
     * You should only use String arrays and primitive types
     * for your implementation.
     *
     * @param array1 - the first array of Strings
     * @param array2 - the second array of Strings
     * @return a new array holding items that occur in both array1 and array2
     */
    public String[] intersection(String[] array1, String[] array2) {
        // TODO: implement this
        return null;
    }

}
Implementing StringOps Your Stringops class should contain four methods: 1. pub1ic int 1inearSearch(String [] array, String query, int 1, int ) 2. pub1ic int binarySearch (String [] sortedArray, String query, int 1 , int ) 3. pub1ic void insertSort(String [] array) 4. pub1ic void swapemSort(String [] array) query was is found, return the index in the array for the specified item. If the query was not found, 1 inearSearch should return . bound. Additionally, as with 1inearSearch, binarySearch should return the index of the query in the array if it is found, and -1 otherwise. The method insertsort should take an unsorted array, and perform insertion sort as discussed in class. The fourth method swapEmSort sorts the array by swapping adjacent elements according to the following procedure: 1. start at the beginning of the String array and compare adjacent elements (i.e., elements 0 and 1). 2. if these elements are out of order, swap them. 3. move one element forward and go back to step (1) (so you are now comparing elements 1 and 2 ). 4. continue steps 1-3 until you reach the end of the array. 5. repeat steps 1-4 until you make an entire pass through the array without performing any swaps. Extra Credit For up to 6 points of extra credit, implement the two set operations union and intersection with the following signatures: 1. public String[] union(String[] array1, String[] array2) 2. pub1ic String[] intersection(String [] array1, String [] array2)


We have an Answer from Expert

View Expert Answer

Expert Answer


Java code for the required program is given below : public class StringOps { /** * _Part 1: Implement this method._ * * Approach: *
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe