301,083 views
26 votes
26 votes
Define an equals method for the class. In our bizarre definition of sequence equality (do not tell your math teacher about this J), we will assume 2 sequences to be equal if they have at least matchCount terms in common. The placement of terms do not have to match. For example, if matchCount is 3, the sequence 1, 2, 3, 4, 5, 6 and 2, 4, 6, 8 would be equal because there are at least 3 number (i.e. 2, 4, and 6) that show up in both sequences. For the same example, the sequences would not be equal had matchCount been set to 4.

User Subdigger
by
2.9k points

1 Answer

23 votes
23 votes

Answer:

Answered below

Step-by-step explanation:

public boolean equals(int[] list1, int[]list2){

int I, j;

int count = 0;

//Loop through both lists using nested loops and increase count if their elements are equal.

for(I = 0; I < list1.length; I++){

for(j=0; j< list2.length;j++){

if(list[I] == list[j]{

count++;

}

}

}

//Check if count is equal to maxCount, return false if not equal otherwise return true.

if(count != maxCount){

return false;

}

return true;

}

User Ben Regenspan
by
2.7k points