| Author |
Help with compareTo()
|
Santhan Rajah
Greenhorn
Joined: Mar 26, 2003
Posts: 3
|
|
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
Joined: Dec 06, 2001
Posts: 3061
|
|
|
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.
|
Java API Documentation
The Java Tutorial
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
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).
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Francis Siu
Ranch Hand
Joined: Jan 04, 2003
Posts: 867
|
|
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
|
Francis Siu
SCJP, MCDBA
|
 |
Santhan Rajah
Greenhorn
Joined: Mar 26, 2003
Posts: 3
|
|
Thanks a lot for your help. I really appreciate it.
|
 |
Gabriel White
Ranch Hand
Joined: Mar 02, 2003
Posts: 233
|
|
|
Glad that your getting help
|
 |
 |
|
|
subject: Help with compareTo()
|
|
|