# Thread: Calendar Fun, Or not so much.

1. Member
Join Date
Oct 2011
Posts
4
Rep Power
0

## Calendar Fun, Or not so much.

I'm attempting to write a simple program that will take in Day Number, Month Number and Year Number from an input box. (In that specific order)

What I'm trying to do is to force the program to check if a given Day Number exists within that specific month. For example, there is no 31st in February, and certain months only have 30 days as opposed to 31 days.

What would be the simplest way to incorporate that kind of check after receiving input for the Day Number and then Month Number, and if it is incorrect, restart the program.

2. ## Re: Calendar Fun, Or not so much.

I'd probably use the Calendar class.

But assuming this is for homework and that's not valid, think about it this way: how would you do this by hand or in your head?

3. Member
Join Date
Oct 2011
Posts
4
Rep Power
0

## Re: Calendar Fun, Or not so much.

Well for months 1, 3, 5, 7, 8, 10 and 12 I would note that the maximum value is 31, and for all other months besides 2, I would assign that value to 30.

My problem is since I'm still too inexperienced with using Java, I was thinking that I could use some kind of a switch statement that says these sets of months can only have this many days. The Issue is since the input order has to be Day Number, followed by Month Number, how do I apply that check

4. ## Re: Calendar Fun, Or not so much.

Just store each value in a variable, and do whatever you want with it.

One way is to use a switch statement and if statements. Why don't you give it a go, post an SSCCE demonstrating what you try, and we'll go from there if you get stuck?

5. Member
Join Date
Oct 2011
Posts
4
Rep Power
0

## Re: Calendar Fun, Or not so much.

What exactly am I storing, I've already created variables for dayNumber, and monthNumber from reading the input dialog box's.

I'm just trying to understand how to properly apply those two variables from the inputs, and make the proper comparison between the two.

6. ## Re: Calendar Fun, Or not so much.

Then I'm not sure what your question is. You've described what you have to do. Where are you stuck? What do you have so far?

7. Member
Join Date
Oct 2011
Posts
4
Rep Power
0

## Re: Calendar Fun, Or not so much.

I actually worked it out. I ended up creating a variable "maxDay" within my switch statement for months, and encased the entire program inside a while loop, basically.

Thank You for the help though.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•