Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (javk):

Java methods and instance methods. I need help with part b)ii) and part c)ii)

OpenStudy (javk):

Disclaimer: this is not the exam paper (or at least the current one), I'm just practicing exam style questions and I got stuck...

OpenStudy (javk):

in part b)ii) does that mean that the equals method for the class already exists or do I have to write that too. this is what I got for part c)i) ``` public static boolean before(Date d1, Date d2) { if (d1.year < d2.year) return true; else if (d1.month < d2.month) return true; else if (d1.day < d2.day) return true; else return false; } ``` I just don't know what to do next

OpenStudy (javk):

@woodrow73 @theEric @abtster @caominhim @e.mccormick @pitamar

OpenStudy (woodrow73):

Lets say d1 year is after d2 year.. like d1 = march(3) 2030, and d2 = september(9)2010 - ``` if (d1.month < d2.month) return true; ``` that code will then execute, then you'll be saying d1 is before d2 based off the month; a different approach is needed for that problem.

OpenStudy (woodrow73):

For b)ii) I would create your own equals method in date class to override the normal (I think it's a method of Object) equals method.. otherwise I think it's just checking whether the 2 date objects share the same reference to memory.. not the dates themselves.

OpenStudy (woodrow73):

For c)ii) seems like it involves OOP and arrays.. what's unclear on that one - how far did you get?

OpenStudy (javk):

Ok thanks, i think i was busier freaking out than actually doing the questions. So like you said i created equals method for date and then the rest of b)ii) was much easier, coz i knew what i was meant to be doing My answer to c)ii) had a glitch, my inner loops should only have been executing when the outer loop was an equivalence…so i fixed that

OpenStudy (javk):

For c)ii) i did: public static String oldName(Student [] stds) { Student oldest=stds[0]; for (int i=0; i<stds.length; i++){ if (Date.before(stds[i].birthDate, oldest.birthdate) == true) oldest = stds [i]; } return oldest.secondName; }

OpenStudy (woodrow73):

Good to hear

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!