Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write one program that implements and calls in main the following methods: A met

ID: 3698311 • Letter: W

Question

Write one program that implements and calls in main the following methods:

A method called indexOf1D that takes as arguments 2 arrays of integers called bigArray and smallArray, that implements for arrays of integers what indexOf does for strings. It checks if smallArray is a subarray of bigArray. If it is not, it returns -1. If it is a subarray, the method returns the index of bigArray where smallArray starts. For example:
indexOf1D({3,1,5,7,2,3,1}, {5,7,2,3}) returns 2 , but
indexOf1D({3,1,5,7,2,3,1}, {5,7,3}) returns -1 because the sequence 5,7,3 is not in {3,1,5,7,2,3,1}.

A method called indexOf2D that takes as arguments 2 2D arrays of integers called bigArray and smallArray, that implements for 2D arrays what indexOf1D does for 1D arrays of integers. It checks if smallArray is a "patch" of bigArray. If it is not, it returns -1. If it is a subarray, the method returns the row and column indexes of bigArray where smallArray starts. For example:

and smallArrays is:

The method will return indexes 0 and 2. You cannot return 2 numbers as 2 separate entities. You must return them as an array of int or an ArrayList.
If the small array is not a 'patch' of the bigArray, return -1 and -1.A method called reverseLines that takes as argument a filename, fnm (e.g. "data1.txt"), and creates another file, fnm_out.txt (e.g. "data1_out.txt"), reverses each line from data1.txt and prints in in data1_out.txt. For example if a file data1.txt contains text:

after the method is called for "data1.txt" a new file called "data1_out.txt" will be created and it will have text:

In order to call these methods from main, you can hardcode the arrays (in main, NOT IN THE METHODS), but allow the user to enter the file name with the data

Explanation / Answer

package com.example.common.utils;

public class ArrayUtils
{

    public int findArray(int[] largeArray, int[] subArray) {

        if (largeArray.length == 0 || subArray.length == 0) {
            return -1;
        }

        if (subArray.length > largeArray.length)
        {
            return -1;
        }

        for (int i = 0; i < largeArray.length; i++)
        {
            if (largeArray[i] == subArray[0])
            {

                boolean subArrayFound = true;
                for (int j = 0; j < subArray.length; j++)
                {
                    if (largeArray.length <= i+j || subArray[j] != largeArray[i+j])
                    {
                        subArrayFound = false;
                        break;
                    }
                }

                if (subArrayFound)
                {
                    return i;
                }

            }
        }

       return -1;
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote