• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

comparisons in an InfiniteInt class  RSS feed

 
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
Rhyeca Riley
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 23713
50
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rhyeca Riley
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Paul Clapham
Sheriff
Posts: 23713
50
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you're on the right track as far as I can see. But it's usually the little things that will bite you!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!