• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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: 59453
187
  • Mark post as helpful
  • send pies
  • 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: 8997
168
  • Mark post as helpful
  • send pies
  • 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: 59453
187
  • Mark post as helpful
  • send pies
  • 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
  • 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: 59453
187
  • Mark post as helpful
  • send pies
  • 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
  • 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: 59453
187
  • Mark post as helpful
  • send pies
  • 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
  • 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: 8997
168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Huh. I'd ask them for an explanation.
 
Leandro Takeda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeap, will do... thanks Stephan!
 
Leandro Takeda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 38394
650
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!