Forums Register Login

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

+Pie Number of slices to send: Send
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


+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1279 times.
Similar Threads
Get the day
Get the day of the week & month in word from constructor into main with input
Help Needed
cannot find symbol inside String?
Subtract 2 Dates
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:09:35.