aspose file tools*
The moose likes Beginning Java and the fly likes problem with compareTo  method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with compareTo  method" Watch "problem with compareTo  method" New topic
Author

problem with compareTo method

Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
Hey yall, Iam having a problem putting this together. This is all the information that I have. I will post the code below. But I am to check if the disks in my Disks are in ascending order, using the compareTo method in the class Disk. Im not to sure about the setMyDisks method as well. I would appreciate any input on this. Thanks in advance.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi Steve,
1. do you just want to check if the disks are in ascending order?
OR
2. do you want to put them in ascending order when you create the list of disks?
if it 1st then I really don't understand why you have to write compareTo() in Disk? again you didn't write "implements Comparable" in the class Disk so...i am not sure why you took that approach...
also there is a compile time error in the code where you call compareTo() in the class ManyDisks because compareTo() is in Disk class not in ManyDisk and you are referring to it as its a instance method.
if you want to perform the 2nd option i mentioned above then you have to make "class Disk implements Comparable" and then make the compareTo() method compatible to equals() method as the Comparable API mentions it.
please let me know what exactly you are trying to do...
regards
maulin.
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
I just want to check to see if the disks are in ascending order using the compareTo method. I know this code is not complete, it is just a shell. I am trying to understand how to use the compareTo method to see if mydisks are in ascending order (theoreticly)(sic)
This is an assignment and I have filled out all of it but the last method. I dont know what to do with it. I am using the compareTo method because that is what the instructor told us to do.
I just need code to put in there that "Should" do the trick.
Thanks
[ March 27, 2003: Message edited by: Steve Wysocki ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Steve, are you supposed to do this by implementing the Comparable interface? If so, the signature of compareTo is int compareTo( Object o ).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
as you can see, I have already started the last method, but I dont see how to use the compareTo method to check if the disks are in ascending order.
Thanks for the replies

[ March 28, 2003: Message edited by: Steve Wysocki ]
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 985

Steve could you please edit your post so that it doesn't cause everyone to have to scroll right. Thanks.


Please ignore post, I have no idea what I am talking about.
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
I kept editing it and I had some problems...lol, sorry about that. You must have caught it right during an edit.
It looks right now.
Thanks bro
Steve
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 985

You didn't answer Barry's question. Depending on your answer to that question will determine how we answer your question.
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
nm, I dont know exactly what Barry is asking. So I will just work on it some more. If I need some more help then I will come on back and post again.
Thanks Bill.
Steve
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
gents, I finally got it.
Again I just needed to "check" to see if the disks were in ascending order. So I used the compareTo method and compared it to -1 and thus returned a false due to i-1. If none of the disks are in order then it will just kick out of the compareTo method with a -1 so I used that...
Anyway, just in case you were interested
This is what I meant in code that is:

[ March 28, 2003: Message edited by: Steve Wysocki ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with compareTo method