-3

I am trying to answer this question, but I have no idea what the author means by "adding N*12".

This is the question:

Write a complete Date class with a constructor new Date(month, day, year) that creates a Date object with the given month, day and year. Use a hypothetical calendar in which every month has 30 days. A day value outside the range 1 through 30 is to be replaced by 1. For a negative month number, add N*12 to it and subtract N from the year, to make the month number 1 through 12. Make the opposite adjustment for month numbers greater than 12.

I have no idea what the variable N is supposed to mean here, and I am trying to figure it out. That is all I want help with.

7
  • N=negative month number Jan 23, 2014 at 11:04
  • N is N, a number. For example, N=42.
    – devnull
    Jan 23, 2014 at 11:04
  • 1
    Choose N such that the resulting month number will be between 1 and 12.
    – Njol
    Jan 23, 2014 at 11:05
  • 4
    Looks like someones homework assignment. Questions regarding homework don't belong on stackoverflow.
    – M. Deinum
    Jan 23, 2014 at 11:07
  • 1
    @M.Deinum Homework questions are OK, as long as OP are not asking to do their homework for them. It appears that OP wants help in understanding the question, not in writing the code for it. Jan 23, 2014 at 11:23

3 Answers 3

2

N says how many years (twelve month intervals) are "built into" the month number. It is a hypothetical number representing one twelfth of the offset to be added to the month or subtracted from it in order to bring the value of the month into its valid range of 1..12. N could be positive, negative, or zero, depending on M - the number of the month. In plain words, N says how many times we need to add or subtract 12 from M in order to bring it into the range of 1..12.

Here are a few examples:

  • M is 8 - Since the month is already in the 1..12 range, N is 0.
  • M is 18 - The month is outside the 1..12 range, so we need to subtract 12 from it in order to bring it into the range. N is -1.
  • M is -38 - The month is negative. We need to add 12 four times in order to bring it into the range, so N is 4.
0
0

N in this case is a number. It's talking about which number you'll need to add, but not saying which because it'll be different in each circumstance.

-1

N is a user input value(i.e. int month) to your method. From what I see, it can be a negative number too

Not the answer you're looking for? Browse other questions tagged or ask your own question.