Calendar in onject way



I have task to solve:

Java Code: Day Create the class Day for representing days in a calendar. The class should include attributes specifying the day: dayOfMonth, month, year. 1. Implement the following public constructors: * Day(int numberOfDaysSinceTheBeginningOfTheEpoch);, where numberOfDaysSinceTheBeginningOfTheEpoch is the number of days that elapsed since some distinguished date like 15.10.1582. * Day(int dayOfYear, int year); * Day(String dayOfWeek, int weekOfYear, int year); * Day(int dayOfMonth, int month, int year); * You might also need a private constructor for initializing the calendar (to be used only once): private Day(int day, int month, int year, String dayOfWeek);. 2. Implement the following public methods: * String dayOfWeek() * String month() * String season() * String academicSeason() * int dayOfYear(), int daysLeft() // the number of days left till the end of the year * int weekOfYear(), int weeksLeft() // the number of weeks left till the end of the year * int monthOfYear(), int monthsLeft() * int year() * boolean isLeapYear() * int daysBetween(Day day) returning the number of days between this and day (might be a negative number!) Remarks * You might need some private helper methods too. * You may assume that all academic seasons start and end the same day each year. 3. Define and use in implementation of methods the following static constants: * Days of week: public final static String MONDAY = "MONDAY"; * month names * season names * academic year terms like: "winter term", "summer term", "holidays", "exams" You will need a static constant to link some particular date to the corresponding day of week. For example: private final static Day TODAY = new Day(17, 12, 2009, Day.THURSDAY); Note * You may use enumerations instead of static constants. 4. Add suitable test/presentation of the methods and constructors in the method main(). mh_sh_highlight_all('java'); And I have something like this but I am not sure about it
maybe someone have idea to improve code or can write it in shorter way:
Thank you.

Java Code: public class Day { //enums public static enum DaysOfWeek { MONDAY("monday",1), TUESDAY("tuesday",2), WEDNESDAY("wednesday",3), THURSDAY("thursday",4), FRIDAY("friday",5), SATURDAY("saturday",6), SUNDAY("sunday",7); private final String dayStr; private final int dayInt; DaysOfWeek(String s,int i) { dayStr=s; dayInt=i; } public String getString() { return dayStr; } public int getInt() { return dayInt; } } //extend these enums public static enum Months { JANUARY("january",1), FEBRUARY("february",2), MARCH("march",3), APRIL("april",4), MAY("may",5), JUNE("june",6), JULY("july",7), AUGUST("august",8), SEPTEMBER("september",9), OCTOBER("october",10), NOVEMBER("november",11), DECEMBER("december",12); private final String monthStr; private final int monthInt; private Months(String s, int i) { monthStr=s; monthInt=i; } public String getString() { return monthStr; } public int getInt() { return monthInt; } } public static enum Seasons { SPRING("spring"), WINTER("winter"), SUMMER("summer"), AUTUMN("autumn"); private String seasonStr; private Seasons(String s) { seasonStr=s; } public String getString() { return seasonStr; } }; public static enum AcademicTerms { WINTER_TERM("winter term"), SUMMER_TERM("summer term"), HOLIDAYS("holidays"), EXAMS("exams"); private String termStr; private AcademicTerms(String t) { termStr=t; } public String getString() { return termStr; } } private static final DaysOfWeek BEGINNING_WEEKDAY=DaysOfWeek.FRIDAY;//mialem z tym problemy bo static i final jednoczesnie!!!!!! private static final Day BEGINNING_DATE=new Day(15,10,1582); private final int D;//day of month private final Months M;//should it be int or Months private final int Y;//year number //constructors public Day(int numberOfDaysSinceTheBeginningOfTheEpoch) { int additionalYears=BEGINNING_DATE.Y; int additionalDays=BEGINNING_DATE.dayOfYear()+numberOfDaysSinceTheBeginningOfTheEpoch; if(additionalDays>0) { while(additionalDays>(isLeapYear(additionalYears)366:365)) { additionalDays-=isLeapYear(additionalYears)366:365; additionalYears++; } } else { // if(additionalYears) while(additionalDays12) { additionalYears++; monthNum=1; } } } //assign vars Y=additionalYears; M=monthToEnum(monthNum); D=additionalDays; } public Day(int dayOfYear, int year) { if(dayOfYear366) throw new IndexOutOfBoundsException("Number of days too big"); if((dayOfYear == 366)&&(!isLeapYear(year))) throw new IndexOutOfBoundsException("Number of days too big"); //find month and day of month int monthNum=0; int daysNum=0; int oldNumDays=0;//just to init while(daysNum
Posted On: Thursday 25th of October 2012 01:52:03 AM Total Views:  390
View Complete with Replies

RELATED TOPICS OF Java PROGRAMMING LANGUAGE