Help with Exercise 92 - Object Oriented Programming 1

745 views
Skip to first unread message

AZ

unread,
Oct 12, 2015, 12:06:51 PM10/12/15
to mooc.fi
Hi,

I'm having problems with week 5 exercise 92.

I have completed the first part but I need help on making the method more accurate.

How do I calculate the difference more accurately for the second part of the exercise?


The link to my work is here: http://paste.mooc.fi/3771e7da

Best regards


Supported languages are English and Finnish

Please use our build in TMC Pastebin when asking questions related to your code  
 
TMC Plugin has built-in code sharing feature. 
In NetBeans, select TMC -> Send code to TMC pastebin. Copy the link you receive and paste it to your message.  

You may use our web interface to share code snippets: http://paste.mooc.fi

ljleppan

unread,
Oct 13, 2015, 4:51:40 AM10/13/15
to mooc.fi, alir...@hotmail.co.uk
Hi,

Consider a method call first.differenceInYears(second) where first and second are MyDate objects.

We have three general cases:
1. Both dates are equal
2. first is before second
3. second is before first

Case #1 is trivial so we skip that. We also notice that cases #2 and #3 are essentially the same, with just the dates inverted. So if we can solve one of those, we know how to solve the other. So let us focus on case #2.

NB: I'll be using the format year/month/day, so 2015/1/2 is January 2nd, 2015.

Let us consider a few sub-cases in the format day.month.year, so :
1. first = 2014/1/2, second = 2015/1/1
2. first = 2013/1/2, second = 2015/1/1
3. first = 2013/1/1, second = 2015/1/2

In sub-case #1, the difference is 0 full years, in #2 it's 1 full year and in #3 it is 2 full years.

I'd like you to write those dates down on paper and figure out the pattern there.

I'll give you one more hint: Sometimes, the correct answer is (first.year - second.year - 1) and sometimes it is just (first.year - second.year).

If you need more help, do not hesitate to ask :)

Yours,
Leo
Reply all
Reply to author
Forward
0 new messages