Forums Register Login

comparisons in an InfiniteInt class

+Pie Number of slices to send: Send
Hey everyone was wondering if I could get some help with a method (compareTo) in my class (InfiniteInt).  I know my logic is not 100% right so I was wanting a push in the right direction. The nodes used are from a Doubly Linked List which InfiniteInt is a subclass from. (dont want to put too much of my code on here so if that is something you need I can put it). Thank you for your time/help!

+Pie Number of slices to send: Send
I guess it would help if I told you what was wrong... The first two cases, less than and greater than are working. The only one not working is if they are equal. I am not getting a 0 but instead a -1.
1
+Pie Number of slices to send: Send
Here's what I notice: lines 19 to 33 always return some value, one of 1 or -1 or zero. That means that lines 34 to 39 can never be executed.

So I'm guessing you meant to put 34 to 39 somewhere else. If your InfiniteInt class is supposed to act like holding an integer with its digits in a linked list, then probably you meant to put them before line 19. I don't think that would solve everything but it would likely be a step forward.

However to me it looks like your code would get a 0 when you compare 1-9-4-9 to 1-6-7-8, rather than the correct value of -1. But you say you have the opposite problem? Then some debugging would help find out what's going on.
+Pie Number of slices to send: Send
Thank you Paul! I was going to start putting in a bunch of S.O.Pln but thought I would post on here first to see if something was compltely messed up first (I often overlook "little" things)
1
+Pie Number of slices to send: Send
No, you're on the right track as far as I can see. But it's usually the little things that will bite you!
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 410 times.
Similar Threads
Dog is not abstract and does not override abstract method
is this correct way of implimenting comparable interface
declare runtime exceptions in javadoc?
Sorting two arrays...
Writing compareTo and equals method with Object arguments
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:12:37.