Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me fix the errors? / * * * * * * * * * * * * * * * * *

Can you help me fix the errors?
/*********************************************************************
*
* METHODS TO BE COMPLETED
*
*
************************************************************************/
/** Check to see if two bags are equals.
* @param aBag Another object to check this bag against.
* @return True the two bags contain the same objects with the same frequencies.
*/
public boolean equals(ArrayBag aBag){
boolean result = true;
T[] t = toArray();
T[] s = aBag.toArray();
for(int i =0; i t.length; i++){
for(int j =0; j s.length; j++){
if(s[j]!= null && s[j].equals(t[i])){
t[i]= null;
s[j]= null;
}
}
}
for(int i =0; i numberOfEntries; i++)
if(t[i]!= null)
result = false;
for(int i =0; i aBag.numberOfEntries; i++)
if(s[i]!= null)
result = false;
// COMPLETE THIS METHOD
return result;
}
// end equals
/** Duplicate all the items in a bag.
* @return True if the duplication is possible.
*/
public boolean duplicateAll(){
checkIntegrity();
boolean success = false;
if(numberOfEntries *2> bag.length)
return success;
for(int i =0; i numberOfEntries; i++)
bag[i + numberOfEntries]= bag[i];
success = true;
// COMPLETE THIS METHOD
return success;
}// end duplicateAll
/** Remove all duplicate items from a bag
*/
public void removeDuplicates(){
checkIntegrity();
if(numberOfEntries =1)
return;
for(int i =0; i numberOfEntries -1; i++){
for(int j = i +1; j numberOfEntries; j++){
if(bag[i].equals(bag[j])){
remove(bag[j]);
j--;
}
}
}
return;
}// end removeDuplicates
}// end ArrayBag
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Instruction Set Architecture ( ISA )

Answered: 1 week ago

Question

2. (1 point) Given AABC, tan A b b

Answered: 1 week ago

Question

f. Did they change their names? For what reasons?

Answered: 1 week ago