The Artima Developer Community
Sponsored Link

Java Answers Forum
please help me with this interface.

1 reply on 1 page. Most recent reply: Feb 10, 2003 6:56 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
diqq

Posts: 3
Nickname: diqq
Registered: Feb, 2003

please help me with this interface. Posted: Feb 10, 2003 6:05 PM
Reply to this message Reply
Advertisement
I only need guidance on how to go about impleting an interface like this:

Public interface Set{
public boolean insert(int i)
public boolean remove(int i)
public boolean member(int i)
}


public class A1 {
public static void main(String[] s1) {
long time1;
long time2;
for (int i =1; i < 5; i++) {
Set s = new LinkedSet();
int j = 0'
time1 = System.CurrentTimeMillis();
for (; j < i * 4000; j++) {
s.insert(j);
}
time2 = System.currentTimeMillis();
System.out.println("insertion of " + j + "elements takes "
+ (time2 - time1) + "milli seconds");

int k = 0;
time1 = System.currentTimeMillis()
for (; k < 1000; k++) {
s.isMember(((int) (Math.random() * i * 10000)) %j);
}
time2 = System.currentTimeMillis();
System.out.println("isMember with " + j + "elements takes "
+ (((double) (time2 -time1)) / k) + "milli seconds");
time1 = System.currentTimeMillis();
for (j = 0; j < i * 4000; j++) {
s.remove(j);
}
time2 = System.currentTimeMillis();
System.out.println("removal of " + j + "elements takes "
+ (time2 - time1) + "milli seconds");
}
}
}


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: please help me with this interface. Posted: Feb 10, 2003 6:56 PM
Reply to this message Reply
What was wrong with the previous answers? Maybe you need to post the whole text of the homework assignment, since it is not clear what you mean by "implement." To implement an interface usually means simply to write a class just as Ryan Shriver did in his answer to your previous posting of this question.

Are you really asking how to implement a set? If so, what are the requirements of your homework assignment? That is, are you not allowed to use any existing Java Collections? Are you supposed to do it "by hand?" Is that what your LinkedSet is? Is your set supposed to be implemented in a LinkedList? If so, are you allowed to use the java.util.LinkedList in your implementation?

Flat View: This topic has 1 reply on 1 page
Topic: solve this problem for me (urgently needed) Previous Topic   Next Topic Topic: help to resolve errors

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use