• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with compareTo method

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve, are you supposed to do this by implementing the Comparable interface? If so, the signature of compareTo is int compareTo( Object o ).
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve could you please edit your post so that it doesn't cause everyone to have to scroll right. Thanks.
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic