Working with dates

  • 10
  • Locked
The Nebula-1 station receives spaceships only on odd days of the standard earth year (i.e. days when there have been an odd number of days since the beginning of the year). Let's find out if we can party on Nebula-1 today. To do this, we'll implement the isDateOdd(String date) method, which returns true if the number of days since the beginning of the year is odd, and otherwise returns false.
You can't complete this task, because you're not signed in.
Comments (11)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Tommy
Level 10, Phoenix, AZ, United States
21 February, 01:59
Here is a tutorial on parsing String to Date that I found incredibly useful in solving this project: https://howtodoinjava.com/java/date-time/java-parse-string-to-date/ Couple that with CodeGym tutorial on this exact problem: https://codegym.cc/quests/lectures/questsyntax.level08.lecture04
Samuel Michael
Level 16, Stafford, United States
5 January, 18:24
JANUARY 1 2000 = true JANUARY 2 2020 = false If the requirement is to return true if the number of days since the beginning of the year is odd, then January 2 2020 should return true because it is 1 (odd) day since the beginning of the year. January 1 2020 is an understandable exception.
ziv fisher
Level 9, Petah Tikva, israel
17 October 2020, 08:24
Determine how many days have passed since the beginning of the year: https://codegym.cc/quests/lectures/questsyntax.level08.lecture04
Vishal Gautam
Level 8, Bangalore, India
13 October 2020, 08:04
Tip: Clone the date object that you initialized by parsing the String parameter. Date newYear = new Date(passedDate.clone().toString()); Set the month and date to 0(Jan) and 1. No need to set the year. Number of days passed since new year = differenceInMilliseconds/(1000*60*60*24) + 1
MoJo
Level 22, Cairns, Australia
31 August 2020, 09:52
Hint: you can set a date to the beginning of the year and increase this in a loop by BeginningOfTheYearDate.setDate(BeginningOfTheYearDate.getDate()+1) . If you do so until it is the same as the input date and keep track of the times you increased the date you can easily determine if the days passed are odd or even.
Hannah
Level 11, Koblenz, Germany
30 July 2020, 10:50
I am currently working on one of your exercises and somehow the Calendar.MONTH isn't working. The Compiler is telling me, that there is no constructor for GregorianCalendar(int,java.lang.String,int). Only java.util.GregorianCalendar.GregorianCalendar(int,int,int). So I guess I will have to write a little method to transform the Month-Word into the corresponding number... Maybe someone can tell me, why Calendar.MONTH isn't working? Am I needed to import another class? Currently I have util.Date; util.Calendar and util.GregorianCalendar; Update: because of the requirement that the Solution class must have two methods, I now have to take everything I have outsorced into my transformMonth method and have to throw it in the isDateOdd method, and everything will be totally incomprehensible
Petros
Level 23, Columbia, United States
26 July 2020, 02:47
Brutal. Couldn't solve it on my own. Had to look at the help section.
Liliane Top
Level 17, Amsterdam, Netherlands
9 March 2020, 18:28
Is there a tutorial on this subject? How to work with Calendar. oracle site is incomprehensible.
Lucas Hoage
Level 14, Savannah, United States
4 June 2020, 18:20
https://codegym.cc/groups/posts/java-time-calendar The oracle documentation contains an argument that can be passed to get the actual day number. But to do so, you will need to pass the value into the new Calendar object you created. To do that you need to figure out how to pass the String into a format that Date can understand. I also recommend using a Ternary Operator on the last part https://codegym.cc/groups/posts/14-ternary-operator
Kent Hervey
Level 16, United States
22 January 2020, 01:17
I suppose this is the hardest one, yet, since I notice number of completions is lowest