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...
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...
write the “largerComponents” method that takes in two integer arrays and returns true or false if...
write the “largerComponents” method that takes in two integer arrays and returns true or false if the first array’s components are strictly greater than the second array’s components. The arrays must be the same size or else return false. Clarification Note: Components meaning each value at a specific index. For instance, if we had the arrays {5,2,7} and {1,3,1} then this method would return false as the value “2” is not greater than “3”. here is a provided code //Do...
You are given two integer arrays a and b of the same length. Let's define the...
You are given two integer arrays a and b of the same length. Let's define the difference between a and b as the sum of absolute differences of corresponding elements: difference = |a[0] - b[0]| + |a[1] - b[1]| + ... + |a[a.length - 1] - b[b.length - 1]| You can replace one element of a with any other element of a. Your task is to return the minimum possible difference between a and b that can be achieved by...
Create a class called Dishwash with a double called CubicFeet, a string called color, and a...
Create a class called Dishwash with a double called CubicFeet, a string called color, and a method called Washing. The Washing method should return a string to the main class with the text "Now washing dishes!" In the main class create an array of DishWasher size 3. Give each DishWasher a different color and CubicFeet. Use a foreach loop to display that info, call the Washing method, and display the text returned from the Washing method call. c#
Define a class called Counter whose internal "count" variable is a basic integer counter. This class...
Define a class called Counter whose internal "count" variable is a basic integer counter. This class track that count from its instantiation in the constructor (can be set to any positive integer, or 0). The count should never be allowed to be negative. Include methods that will set the counter to 0, increase the count by 1, and decrease the count by 1. Include an accessor method that returns the current count value (getCount()). There should be no input /...
In BlueJ, create a project called Lab6 Create a class called LineSegment –Note: test changes as...
In BlueJ, create a project called Lab6 Create a class called LineSegment –Note: test changes as you go Copy the code for LineSegment given below into the class. Take a few minutes to understand what the class does. Besides the mutators and accessors, it has a method called print, that prints the end points of the line segment in the form: (x, y) to (x, y) You will have to write two methods in the LineSegment class. There is information...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT