• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with compareTo()

 
Santhan Rajah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Can anyone tell me what�s wrong here?
Pls, any help is appreciated.
Here is my code:
import java.util.*;

class Testa implements Comparable
{
public static void main (String argv [] )
{
String one="one";
String two="two";
int number=compareTo();

}
public static int compareTo()
{
int resultat=one.compareTo(two);
return resultat;
}
}
---------------------------------------------
Here is the compiler errors:
G:\Documents and Settings\Santhan\My Documents\Java\Testa.java:4: Testa should be declared abstract; it does not define compareTo(java.lang.Object) in Testa
class Testa implements Comparable
^
G:\Documents and Settings\Santhan\My Documents\Java\Testa.java:18: cannot resolve symbol
symbol : variable two
location: class Testa
int resultat=one.compareTo(two);
^
G:\Documents and Settings\Santhan\My Documents\Java\Testa.java:18: cannot resolve symbol
symbol : variable one
location: class Testa
int resultat=one.compareTo(two);
^
3 errors
Tool completed with exit code 1
[ April 26, 2003: Message edited by: Santhan Rajah ]
[ April 26, 2003: Message edited by: Santhan Rajah ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will you please post the compiler errors that you get? This will help us teach you what they mean so that you will know when you get similar errors in the future.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a good look at the first compiler error? What's it saying?
It's saying that your class doesn't have a method called compareTo that takes an Object as the only argument.
The Testa class declaration says that it implements Comparable. The Comparable interface declares a method named compareTo that takes an Object as the only argument. So, the Testa class must implement such a method (or the class must be declared to be abstract).
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can copy and paste it to the compiler to run the programme and get the result
I hope that I can help you to finish programme
 
Santhan Rajah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your help.
I really appreciate it.
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad that your getting help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic