• 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

Finding the difference between two dates (without using joda or calendar)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, there. I need a little help writing a program in java that will find the difference between two dates, using only months and years. I have just about all of my code written out. Unfortunately, when entering certain months, the desired output is not given. I've looked over all my math and code and everything seems to be in order, so I can't figure out why some dates work and others do not. Towards the bottom of my program, you can see where I attempted to convert years to months in the case of a negative amount of months being reached. Am I doing that part correctly? In case anyone is wondering, I know it would be much easier to simply use the number value of each month. However, my teacher stressed that the whole month must be spelled out. This assignment is due on wed. and I'm completely lost. Below you will find my current code. Any help would be greatly appreciated : )
- Aaron


 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aaron, welcome to the Ranch!

At first I thought your code looked just fine. But you seemed to think it isn't, and you're the one who has run some tests on it. So I looked closer and I think I see some cases which aren't handled quite correctly. But you've done the tests: which values of the input are the ones which give the incorrect output? If you can see a pattern there, that's the first step in debugging the code.
 
Aaron Clayton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help and the warm welcome. I actually went to tutoring and I figured out why I was having a couple of issues. I can't believe i missed that tiny month1/month2 issue in my if statements. Everything works great now. I'm glad to have that weight off of my shoulders. At least until the next project starts haha. Thanks again and take care. I'm sure I'll have more questions in the near future.

- Aaron
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic