Results 1 to 10 of 10
  1. #1
    kumalh is offline Member
    Join Date
    Jul 2011
    Posts
    16
    Rep Power
    0

    Default Creating and implementing class for creating a calendar object

    Hi, so I have to create and implement a class for creating calendar objects. Some of the behaviours that the class has to do is:

    - Print a display for a given month and year
    - Print a display for the current month
    - Get the current date
    - Set the current date
    - Roll the calendar date forward or backward by a given number of days or months
    - A toString() method.

    I also have to provide a selection of constructors with default values for the variables.

    Now.. I have absolutely, no f*****g clue of what to do. I don't even know where to start. Please, please, please, could somebody give me a nudge in the right direction of where to start?

    Thanks in advance.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Surprise: it has been done for you; read the API documentation for the Calendar and GregoreanCalendar classes.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    kumalh is offline Member
    Join Date
    Jul 2011
    Posts
    16
    Rep Power
    0

    Default

    Thanks for the reply JosAH. However, that doesn't really help. I know it's all there already, but I'm required to write out my own class myself.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    First list the data the calendar class needs to hold.
    Those are your attributes.
    Provide a constructor that takes values to populate those attributes.

    That list above is the list of methods it needs to provide.

    Start with that. Then pick one of the methods above and try and code it.

  5. #5
    kumalh is offline Member
    Join Date
    Jul 2011
    Posts
    16
    Rep Power
    0

    Default

    Ok. so for my attributes, so far I know that I need an attribute for the current date, and an attribute for the 'first year'.

    The constructors are what's confusing me the most to be honest. I don't understand how to actually create the calendar object.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Do they want you to reinvent the wheel and implement your own Calendar class? If so, google for 'Zeller's congruence'; it has all the date functionality you'll need.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    kumalh is offline Member
    Join Date
    Jul 2011
    Posts
    16
    Rep Power
    0

    Default

    Haha yeh, pretty much. But it's just to test our understanding of creating classes and objects and whatnot. But that doesn't mean I can't use methods from the Calendar and GregorianCalendar classes.

    Regarding zeller's congruence, I am already quite familiar with it. But all that gives me is the first day of the month, and although that will help me down the track, I'm still quite far away from using it.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by kumalh View Post
    Regarding zeller's congruence, I am already quite familiar with it. But all that gives me is the first day of the month, and although that will help me down the track, I'm still quite far away from using it.
    You haven't read close enough: Zeller's congruence gives you the Julan day number given a Gregorean date. The difference of two Julian day number is the difference in days between those two dates; that's all you need.

    kind regards,

    Jo
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    kumalh is offline Member
    Join Date
    Jul 2011
    Posts
    16
    Rep Power
    0

    Default

    JosAH - Sorry, for the misunderstanding.. But still, my understanding of zeller's congruence doesn't matter at this point. Right now, I'm having trouble with starting off. E.g - what do I write for the various constructors of my calendar class, and how to write the different behaviours I outlined in the original post.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

Similar Threads

  1. Help creating a calendar in Java
    By bars225 in forum New To Java
    Replies: 11
    Last Post: 06-18-2011, 09:16 PM
  2. Replies: 3
    Last Post: 09-29-2010, 09:26 AM
  3. Replies: 2
    Last Post: 03-08-2010, 10:29 AM
  4. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 03:33 PM

Tags for this Thread

Posting Permissions

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