Thanks for the well-thought question. Far too often I've seen people simply ask for the solution without much thought put into the matter - it's nice for a change of pace.
As for the core matter, you seem to have the matter pretty well-in-hand for the error checking and month transformation. Your idea for constants is a good one, but I might suggest that you make the value the month position as opposed to the days in the month. This will be more useful should you ever wish to extend the program in the future, as well as possibly make your program more readable. What you could then do is create an array that contained the number of days for each month. For instance :
Code:
static final int JANUARY = 0;
static final int FEBURARY = 1;
static final int MARCH = 2;
.
.
.
static final int DECEMBER = 11;
static final int[] DAYS_IN_MONTH = { 31, 28, 31, . . . , 31};
int daysOfMarch = DAYS_IN_MONTH[MARCH];
At least I think that would be pretty easy to understand. Of course, dealing Feburary is going to be confusing and a hack, but that would be the case regardless.
Now, as to the problem of the day of the year, I would think simply running through and adding each element in the array up to the month specified, followed by adding the day of the month would yield the total number of days in the year. Let me know if that makes sense to you or not - if not I can provide some code examples.
Now, there is an alternate way to go about this and I think it's important for you to know how to do this. A friend once told me that for most problems in computer science, they have already been solved by people who are specialists in the field and have many more years of experience than us. It doesn't make sense to try to re-invent the wheel when someone's probably already done it and done better than we could, so just take what's already available. In this case, I'm referring to the
Core Library of Java. Or more specifically, the
Calendar object. It provides all the functionality you need, all you need to do is find out how to use it and very little further effort is needed on your part. As a new programmer (or even as an experienced programmer), any time you work in Java, you should have the API open for quick reference. You'll be surprised just how many things are automatically provided for you. The art of finding out how to use the tools provided is just as important (probably even more so) to a programmer than how to build your own.