Question

In: Computer Science

Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The...

Details:

Create a class called CompareArrays that determines if two specified integer arrays are equal.

The class should have one static methods:

  • public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false.

NOTE: You are not allowed to use the Arrays.equals method for this programming assignment.

Create a second class called CompareArraysTest that contains the main method, and thoroughly tests the ComparyArrays.compare method. This test class does not need to ask users for input. Just create the needed arrays to ensure that you test the ComparyArrays.compare method well. The thoroughness of your testing in will impact your grade.

Solutions

Expert Solution

Source Code:

Output:

Code in text format (See above images of code for indentation):

import java.util.*;

/*class definition*/

class CompareArrays

{

    /*static method to compare two arrays*/

    public static boolean compare(int[] arrayOne, int[] arrayTwo)

    {

        boolean check=true;

        /*if lengths are not equal then return false*/

        if(arrayOne.length!=arrayTwo.length)

            return false;

        else

        {

            /*check for same size and same order*/

            for(int i=0;i<arrayOne.length;i++)

            {

                /*if order is missed then return false and break*/

                if(arrayOne[i]!=arrayTwo[i])

                {

                    check=false;

                    break;

                }

            }

            /*return check*/

            return check;

        }

    }

}

/*class to test above method**/

public class CompareArraysTest

{

    /*main method*/

    public static void main(String[] args)

    {

        /*two arrays initialization*/

        int[] arrayOne={12,3,3,4,5};

        int[] arrayTwo={12,3,3,4,5};

        /*method call*/

        boolean check=CompareArrays.compare(arrayOne,arrayTwo);

        /*print equal or not equal*/

        if(check)

            System.out.print("Equal");

        else

            System.out.print("NotEqual");

    }

}




Note:

The above code doesn't read input from the user as mentioned in the question


Related Solutions

Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.”
Programming Problem 2 - Cycle[A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list.[B] Edit your class Cycle by...
Programming Problem 2 - Cycle [A] Create a class called “Cycle” which has two instance integer...
Programming Problem 2 - Cycle [A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list. [B] Edit your class...
Write a function called splice() that “splices” two integer arrays together by first allocating memory for...
Write a function called splice() that “splices” two integer arrays together by first allocating memory for a dynamic array with enough room for both integer arrays, and then copying the elements of both arrays to the new array as follows:             first, copy the elements of the first array up to a given position,             then, copy all the elements of the second array,             then, copy the remaining elements in the first array. The function should have parameters for...
follow pseudo 1) Create class called Node Declare private integer called data (or any other name)...
follow pseudo 1) Create class called Node Declare private integer called data (or any other name) Declare private Node called link (or any other name) 2) Declare constructor Should be public (ex: Node) where: link is equal to null data is equal to zero 3) Declare another constructor public Node with parameters integer d, Node n where: data is equal to d link is equal to n 4) Declare function to set link to next Node link equal to n...
Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes...
Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name. B. Create a CIS22C Dollar derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US...
A. Create a Dollar currency class with two integer attributes and one string attribute, all of...
A. Create a Dollar currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name. B. Create a CIS22C Dollar derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US Dollar. The value of the conversion...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
In C++, there are 4 students that are running for class president. Create three arrays: the...
In C++, there are 4 students that are running for class president. Create three arrays: the candidate’s name, the number of votes the candidate receives, and the candidate’s percentage of the total votes. Your program should be broken down into at least 3 functions: find the total number of votes, calculate values for the percentage each candidate received, and sort the number of votes from highest to lowest. Write the candidate’s name, the total number of votes they received, and...
Modify the HighArray class to implement the method specified below, which reads integer data from a...
Modify the HighArray class to implement the method specified below, which reads integer data from a file to fill the array. The first integer read from the file should indicate the number of integers contained in the file which can be read into the array. /** * Read integers into array from named file. First element in * file is a count of number of integers contained in the file. * * @param fileName   name of file containing integer data...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance of Dog and use its methods. Purpose: This application provides experience with creating classes and instances of objects in C#. Requirements: Project Name: Dog Target Platform: Console Programming Language: C# Documentation: Types and variables (Links to an external site.) (Microsoft) Classes and objects (Links to an external site.) (Microsoft) Enums (Links to an external site.) (Microsoft) Create a class called Dog. Dog is to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT