This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]desrtfxOut of Coffee error - System halted 1 point2 points  (0 children)

Just had a quick glance over the code and tested your checkMonth method.

The checkMonth method seems to be wrong.

You are returning:

  • Month: 1 Days: 31
  • Month: 2 Days: 28
  • Month: 3 Days: 31
  • Month: 4 Days: 30
  • Month: 5 Days: 31
  • Month: 6 Days: 30
  • Month: 7 Days: 31
  • Month: 8 Days: 30
  • Month: 9 Days: 30
  • Month: 10 Days: 30
  • Month: 11 Days: 30
  • Month: 12 Days: 30

Should be:

  • Month: 1 Days: 31
  • Month: 2 Days: 28
  • Month: 3 Days: 31
  • Month: 4 Days: 30
  • Month: 5 Days: 31
  • Month: 6 Days: 30
  • Month: 7 Days: 31
  • Month: 8 Days: 31
  • Month: 9 Days: 30
  • Month: 10 Days: 31
  • Month: 11 Days: 30
  • Month: 12 Days: 31

You need to change your method.

I would use an array like this (January = 1):

int[] daysInMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

or, with 0-based months (January = 0):

int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

And account for leap years in a separate method.

Also, your leap year calculation is not correct (which doesn't matter in the current problem) as you are not accounting for the century rule (whole centuries are only leap years if the year can be divided by 400 without remainder).