Results 1 to 7 of 7
  1. #1
    iasa15 is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default 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. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default 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?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    iasa15 is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default 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. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default 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?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    iasa15 is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default 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. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default 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?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    iasa15 is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Default 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.

Similar Threads

  1. Replies: 4
    Last Post: 09-21-2011, 05:39 PM
  2. Calendar Help Please
    By loopsnhoops in forum New To Java
    Replies: 4
    Last Post: 05-24-2011, 11:35 AM
  3. How to add a calendar????
    By zifis in forum New To Java
    Replies: 5
    Last Post: 04-07-2009, 05:04 PM
  4. calendar
    By John in forum SWT / JFace
    Replies: 12
    Last Post: 08-07-2008, 11:54 PM
  5. Web calendar
    By Daniel in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 06-27-2007, 06:36 PM

Posting Permissions

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