I have to determine whether a year is a leap year or not when the user inputs the year. Example below: Enter year: 2016 2016 is a leap year Enter year: 2013 2013 is not a leap year I have no idea where to start as my professor did not explain it very well in his notes. Can somebody please help me.
on 2016-09-26 01:16
on 2016-09-26 08:29
Ryan, you go to wikipedia and find out how to calculate whether or not a year is a leap year. Then you implement it in ruby. That's how you're going to learn the most from the task. Hint: You'll probably need a class with a method: is_leap_year? After that's working you can think about printing the message to the terminal.
on 2016-09-29 11:34
Joe Gain wrote in post #1185078: > Hint: You'll probably need a class with a method: is_leap_year? After > that's working you can think about printing the message to the terminal. I would not create a class just for this. What instance variables should the class have? Instead I would do one of the following: (1) Put the method is_leap_year? into Fixnum class Fixnum def is_leap_year? ... end end (2) Likewise, put the method into Time and name it then more appropriately is_in_leap_year? (3) Create a module for this - for instance DateUtilities - and make it a module method, like this: module DateUtilities extend self def is_leap_year?(year) ... end end