Hi,
I'm trying to write a Date Class, but I'm having trouble defining it.
So my class have the following fields:
-Year
-Month
-Day
I want a method to calculate the number of days since that date. And I want a few constants (i.e. leap = 4). But I'm not sure where should I put the method and the constant?? Should I keep it in the Date class? If I keep the constant in the date class, will it increase the size of Date?
Start with a different perspective: What methods does your date class need to support? Your internal representation might just be the integer number of days since 1-1-1970, or something else completely. Until we know what you need to accomplish, telling you how best to accomplish it is almost impossible.
To be more specific, I'm trying to convert a Gregorian date to a Hebrew date, vice versa. I want the following method:
- gregYearToHebrew(int year)
- hebrewYearToGreg(int year)
- gregMonthToHebrew(int month)
- hebrewMonthToGreg(int month)
Another one for day, hour, minute, second (halakhim in Hebrew). To convert these, I need constants such as:
year = 365 days
day = 24 hours
hour = 60 minutes
minute = 60 seconds
And of course, constant related to Hebrew dates. Lolz, is this any clearer? I feel like I'm back at spot one.
Last edited by sourlemon; 02-06-2010 at 10:00 PM.
defining constants:
static variables aren't instanced, so no excessive memory is allocated.Code:final static public int YEAR = 365;
Is this meant to be a conversion class, or actually store dates? The two are quite different. A conversion class won't actually require any data storage, but a date object should really have "assign[type]" and "return[type]" methods.
Sinipull, how can I use that variable in nonstatic method?
WingedPanther, I'm not sure I understand what you mean, but I think mine lean toward the store dates. It's similar to a GregorianCalendar class, only with one extra constructor, which is to take an input of a Gregorian date and turn it into a Hebrew date. It also has a method to display the Hebrew instance into a Gregorian Date. Something like this:
HebrewCalendar date = new HebrewCalendar(GregorianCalendar x);
date.toString() - display as hebrew date
date.toGregorianString() - display as Gregorian date
Of course, these methods has to call to other methods which may use the same constant.
Lolz, I'm not sure if that makes it any clearer. Thank you for helping me out. I really appreciate this![]()
Last edited by sourlemon; 02-07-2010 at 08:23 PM.
You can use any static variable in non-static method. Static variables are available from anywhere. You can access them:Code:Sinipull, how can I use that variable in nonstatic method?
if they are located in the same class, as the method accessing them, then no Class name is needed.Code:YourClass.yourVariable
you're awesome! I totally forgot about that. I was too focus on the class. Thank you.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks