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

Define a Mergeable interface with a single (abstract) method merge(): public int

ID: 3633447 • Letter: D

Question

Define a Mergeable interface with a single (abstract) method merge():

public interface Mergeable
{
Object merge(Object x);
}
. Design and write a separate public class IntegerSet that implements Mergeable ? An IntegerSet stores a set of integers, for example, in an array of unique (non-duplicate) ints, and is defined as follows:
• Attributes (private instance variables) – declare these, but don’t initialize them:
– An int[], intSet (the set of unique integers associated with the IntegerSet)
– An int, size (the size of that associated set of unique integers)

• Constructors
– A no-argument constructor that sets both attributes to "empty" or 0 values
• Creating an “empty” intSet array means: intSet = new int[0]; // size 0
– A 2-argument constructor with parameters int[] intSet and int size
• You must eliminate any duplicate ints in the incoming intSet array


Explanation / Answer

Hi, the requirements here are a bit fuzzy, especially about getting rid of duplicates and how that affects the size and the remaining array, should it be done at constructor level or after it's assigned, should you use a helper method or not, should the merge method throw an exception or have you not covered those yet, etc

So I just went with my own assumptions and even if this doesn't match up with what you need perfectly, then I'm sure it will give you a good starting point :) So please rate if it was helpful

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