• 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

Is this question correct or am I missing anything? LocalDate.now() previous one year question

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which statement always returns a date exactly one year before the time if the given statement is run?

Select TWO options:

LocalDate lastYear1 = LocalDate.now().minus(Period.of(1, 0, 0));
LocalDate lastYear2 = LocalDate.now().minus(1, ChronoUnit.YEARS);
LocalDate lastYear3 = LocalDate.now().minus(365, ChronoUnit.DAYS);
LocalDate lastYear4 = LocalDate.now().minusYears(1);

All of them returned the same result:

E.g.:

2017-06-27
2017-06-27
2017-06-27
2017-06-27
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try starting from 2016‑06‑27
Have you read the documentation for those methods of the LocalDate object?
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question is ambiguous (what is an exact year?), but I still believe there are three correct answers. The only one that is obviously wrong is lastYear3.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was getting a bit confused by the documentation,, but if Stephan is correct and there are three right answers, then I shall worry a lot less.

OP: Please always say tell us where such questions come from, to reduce copyright issues, and so we can verify the original
 
Leandro Takeda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, thanks for the help, and you are correct, I should have provided my thoughts about the documentation and I guess this question is not 100% clear. It´s, as you mentioned, ambiguous.

All the answers would be correct, except for lastYear3 because we will have years with not exactly 365 days, also as called "leap years".

This is from Whizlabs by the way.

Thanks!
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure you have copied the question exactly? I should have thought that Whizzlabs would have checked their questions carefully.
 
Leandro Takeda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I did, I´m not sure If I can paste a screenshot here? I guess not.

I reviewed the question again and yes, it´s exactly the same!
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We usually don't like screenshots for reasons explained here, but in these circumstances a screenshot would be OK. When you are replying, click the “attachments” tab.
 
Leandro Takeda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There you go...
Screen-Shot-2018-06-27-at-3.03.08-PM.png
[Thumbnail for Screen-Shot-2018-06-27-at-3.03.08-PM.png]
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huh. I'd ask them for an explanation.
 
Leandro Takeda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeap, will do... thanks Stephan!
 
Leandro Takeda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whizlabs replied me and they pointed me to the "minusYear" method, as you see in the screenshot, the s is missing :/

So, it´s not minusYear. It´s minusYears, in the plural, so last lastYear1 and lastYear2 are the correct ones.

Now, a question for you guys which, of course, are more experient than me, does this kind of question really appear in the exam?

Thanks!
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. While the exam does enjoy tricking you, it doesn't enjoy tricking you on whether you missed one character in a method name. (Unless it is one that is highlighted in the cert books. For example Collections.sort exists. And there is a Collection class so that could in theory come up.

But year vs years. No.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic