• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help in Implementing a Set Interface

 
Yel Chan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm new to Java and I badly need help on how to implement the Set interface below:

Set.java

public interface Set {

public Set union(Set S);

public void add(Object x);

}



I have this code:

Test.java

public class Test implements Set{

public Set union (Set A){

}

public void add(Object x){

}

public static void main (String args[]){

Set A = new MySet();


}

}


Can you help me on how the methods should be implemented. I wanted to add an array to Set A and add values on that array. Then I'm going to pass those array to the union method. Thanks much.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java api has some Set implementation[like HashSet,TreeSet] .there is also method called addAll for your union function. you dont need to implement your self.
what is MySet which in your code? you mean Test right?. apart from this if you want to implement Set data structure yourself. then you need to google much first
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This conversation is also here:
http://www.javaprogrammingforums.com/object-oriented-programming/4883-need-help-interface-function.html

Firstly, we're not talking about the java.util.Set interface, I assume we're talking about an interface used for teaching.

To use an interface:
1) create a class that implements the interface
2) either write all of the methods or declare the Class abstract. You will almost always want to implement all of the methods.

I'll get you started:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic