Kalendarz - problem

0

Witam,
mam taki o to problem... Jestem dość świeży w Javie, a muszę dokonać pewnych zmian w swoim programie... Chciałbym zmienić "public final static String MONDAY = "MONDAY";" na "public enum Day"
zgodnie z: http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html lecz nie daje rady tego zaimplementować. Deadline mam jutro, a niestety jest to warunek, który program musi spełnić.

Byłbym wdzięczny za dokonanie modyfikacji choćby dni z resztą sobie poradzę...

Z góry dziękuję wszystkim.

import javax.swing.JOptionPane;
public class Day {
       public final static String MONDAY = "MONDAY";
       public final static String TUESDAY = "TUESDAY";
       public final static String WENDSDAY = "WENDSDAY";
       public final static String THURSDAY = "THURSDAY";
       public final static String FRIDAY = "FRIDAY";
       public final static String SATURDAY = "SATURDAY";
       public final static String SUNDAY = "SUNDAY";
       
       public final static String JANUARY = "JANUARY";
       public final static String FEBRUARY = "FEBRAURY";
       public final static String MARCH = "MARCH";
       public final static String APRIL = "APRIL";
       public final static String MAY = "MAY";
       public final static String JUNE = "JUNE";
       public final static String JULY = "JULY";
       public final static String AUGUST = "AUGUST";
       public final static String SEPTEMBER = "SEPTEMBER";
       public final static String OCTOBER = "OCTOBER";
       public final static String NOVEMBER = "NOVEMBER";
       public final static String DECEMBER = "DECEMBER";
       
       public final static String WINTER = "WINTER";
       public final static String SUMMER = "SUMMER";
       public final static String AUTUMN = "AUTUMN";
       public final static String SPRING = "SPRING";
       
       public final static String WINTER_TERM = "WINTER TERM";
       public final static String SUMMER_TERM = "SUMMER TERM";
       public final static String HOLIDAYS = "HOLIDAYS";
       public final static String WINTER_EXAMS = "EXAMS";
       public final static String SUMMER_EXAMS = "EXAMS";
       
       public final static Day TODAY = new Day(16, 01, 2010, Day.TUESDAY);
       public final static Day EPOCH = new Day(15, 10, 1582);
       
       int day;
       int month;
       int year;
       int dayOfYear;
       int dayOfMonth;
       int weekOfYear;
       String dayOfWeek;
       
       String season=season();
       
       static int numberOfDaysSinceTheBeginningOfTheEpoch;
       
       
       //constructors
       //Konstruktor ktory tworzy obiekt typu day w ktorym bedzie zapisana liczba dni od 'poczatku'. nie wiem po co to jest wlasciwie.
       public Day(int numberOfDaysSinceTheBeginningOfTheEpoch) {
          this.numberOfDaysSinceTheBeginningOfTheEpoch=numberOfDaysSinceTheBeginningOfTheEpoch;
       }
       //Konstruktor tworzacy obiekt typu day z dwoma wartosciami typu int: dniem od poczatku roku i rokiem.
       public Day(int dayOfYear, int year) {
          this.year = year;
          this.dayOfYear = dayOfYear;
       }
       //Konstruktor tworzacy obiekt typu day z trzema wartosciami: string zawierajcy dzien tygodnia oraz
       //dwa inty: jeden pokazuje ktory to tydzien z kolei w roku, drugi to po prostu rok
       public Day(String dayOfWeek, int weekOfYear, int year) {
          this.dayOfWeek = dayOfWeek;
          this.weekOfYear = weekOfYear;
          this.year = year;
       }
       //Konstruktor tworzacy obiekt typu day z trzema wartosciami int: dzien miesiaca, numer miesiaca i znowu rok
       public Day(int dayOfMonth, int month, int year) {
       
          day = dayOfMonth;
          this.month = month;
          this.year = year;
          
       }
       //Konstruktor ktorego uzywamy tylko raz i ktory sluzy tylko do stworzenia TODAY. w stworzonym obiekcie typu day
       //zawarta bedzie data (dzien, miesiac, rok) oraz dzien tygodnia jako string
       private Day(int day, int month, int year, String dayOfWeek) {
          if (month>12) {
             JOptionPane.showMessageDialog(null,"Month number cannot be greater then 12!");
             System.exit(0);
          }
          this.month = month;
          this.day = day;      
          this.year = year;
          this.dayOfWeek = dayOfWeek;
          
       }   
       
       //method
       
       int dayOfYear() {
          int result = 31 * month - day;
          if (month>=2)
             result=result-3;
          if (month>=4)
             result=result-4;
          if (month>=6)
             result=result-5;
          if (month>=9)
             result=result-6;
          if (month>=11)
             result=result-7;
          if (isLeapYear()&&month>=2)
             result++;         
          return result;
       }
       
       int daysLeft() {
          int result = 31 * month - day;
          if (month>=2)
             result=result-3;
          if (month>=4)
             result=result-4;
          if (month>=6)
             result=result-5;
          if (month>=9)
             result=result-6;
          if (month>=11)
             result=result-7;
          if (isLeapYear())
             result++;   
          if (isLeapYear())
             result=366-result;
          else
             result=365-result;
          return result;
       }
       int weekOfYear() {
          int result = 31 * month - day;
          if (month>=2)
             result=result-3;
          if (month>=4)
             result=result-4;
          if (month>=6)
             result=result-5;
          if (month>=9)
             result=result-6;
          if (month>=11)
             result=result-7;
          if (isLeapYear())
             result++;         
          result=result/7;
          return result;
       }
       
       int weeksLeft () {
          int result = 31 * month - day;
          if (month>=2)
             result=result-3;
          if (month>=4)
             result=result-4;
          if (month>=6)
             result=result-5;
          if (month>=9)
             result=result-6;
          if (month>=11)
             result=result-7;
          if (isLeapYear())
             result++;         
          result=result/7;
          result=52-result;
          return result;
       }
       
       public int monthsLeft() {
          int result=12-month;
          
          return result;
       }
       
       public String month() {
          String result="";
          if (month==1)
             result= JANUARY;
          if (month==2)
             result= FEBRUARY;
          if (month==3)
             result= MARCH;
          if (month==4)
             result= APRIL;
          if (month==5)
             result= MAY;
          if (month==6)
             result= JUNE;
          if (month==7)
             result= JULY;
          if (month==8)
             result= AUGUST;
          if (month==9)
             result= SEPTEMBER;
          if (month==10)
             result= OCTOBER;
          if (month==11)
             result= NOVEMBER;
          if (month==12)
             result= DECEMBER;
          return result;
       }
       
       public String toString() {
          String result="";
          if (day!=0)
             result = result+day;
             if (day==1)
                result = result + "st ";
             if (day==2)
                result = result + "nd ";
             if (day==3)
                result = result + "rd ";
             if (day>3)
                result = result + "th ";
          
          if (dayOfMonth!=0)
             result = result+dayOfMonth+" ";
             
          if (month!=0)
             result = result+month()+" ";
          
          if (year!=0)
             result = result+year+" ";
             
          if (dayOfWeek!=null)
             result=result+dayOfWeek+" ";
             
          if (dayOfYear!=0)
             result=result+"Day of year: "+dayOfYear+" ";
          
          if (weekOfYear!=0)
             result=result+"Week of year: "+weekOfYear+" ";
             
          return result;
       }
       
       public boolean isLeapYear() {
          if (((year%4==0) && (year%100!=0)) || (year%400==0))
             return true;
          else
             return false;
       }
       
       public String season() {

          String result="";
          if ((day>=21 && month>=3) || (day<=22 && month<=6))
             result=SPRING;
          if ((day>=22 && month>=6) || (day<=23 && month<=9))
             result=SUMMER;
          if ((day>=23& month>=9) || (day<=22&& month<=12))
             result=AUTUMN;
          if ((day>=22 && month>=12) || (day<=21 && month<=3))
             result=WINTER;   
          return result;
       }
       public int year() {
          
          return year;
       }
       public String academicSeason() {
 
          String result="";
          if ((day>=30 && month>=9) || (day<=30 && month<=1))
             result=WINTER_TERM;
          if ((day>=1 && month>=3) || (day<=21 && month<=6))
             result=SUMMER_TERM;
          if ((day>=2& month>=7) || (day<=30&& month<=9))
             result=HOLIDAYS;
          if ((day>=1 && month>=2) || (day<=13 && month<=2))
             result=WINTER_EXAMS;
          if ((day>=22 && month>=6) || (day<=2 && month<=7))
             result=SUMMER_EXAMS;   
          return result;
       }

       public String dayOfWeek() {
          String result="";
          int M = (1 + (month + 9) % 12) ;
          if (M>10)
              year--;
          int C = (year / 100);
          int D = (year % 100);
          int dow = ((((13*M-1) / 5) + D + (D / 4) + (C / 4) + (5*C) + day) % 7) ;
          if (dow==0)
             result=MONDAY;
          if (dow==1)
             result=TUESDAY;
          if (dow==2)
             result=WENDSDAY;
          if (dow==3)
             result=THURSDAY;
          if (dow==4)
             result=FRIDAY;
          if (dow==5)
             result=SATURDAY;
          if (dow==6)
             result=SUNDAY;
          
          return result;
       }

       public int daysBetween(Day day) {
          int result = 0;
          int leap = 0;
          int year1 = year;
          int year2 = day.year;
          for (int i=(year1); i<(year2);i++) {
             if (((i%4==0) && (i%100!=0)) || (i%400==0))
                leap++;
          }
          if (year1==year2) {
                result=day.dayOfYear()-dayOfYear();
          } else result=((year2-year1)*365)+leap-(dayOfYear()-day.dayOfYear());
          
          if (result<0)
             result=result*(-1);
          return result;
       }
          
        public static void main(String[] args) {
           Day epoch = new Day(EPOCH.daysBetween(TODAY));
           System.out.println("Today is: "+TODAY);
           System.out.println("Number of days since 15.10.1582: "+numberOfDaysSinceTheBeginningOfTheEpoch);
           System.out.println("The season is: "+TODAY.season());
           System.out.println();
           Day b1 = new Day(2, 10, 1990);
           Day b2 = new Day(15, 8, 2012);
           Day b3 = new Day(23, 4, 3040);
            System.out.println(b1+" is "+b1.dayOfWeek());
            System.out.println(b1.month());
            System.out.println("Academic season: "+b1.academicSeason());
            System.out.println();
            System.out.println(b2);
            System.out.println("Season: "+b2.season());     
            System.out.println("Week of year: "+b2.weekOfYear());
            System.out.println("Weeks left: "+b2.weeksLeft());
            System.out.println();
            System.out.println(b3);
            System.out.println("Day of year: "+b3.dayOfYear());
            System.out.println("Days left: "+b3.daysLeft());
            System.out.println();
            Day c1 = new Day(241, 2007);
            System.out.println(c1);
            System.out.println(c1.year());
            System.out.println();
           Day d1 = new Day(MONDAY, 5, 2001);
           System.out.println(d1);
           System.out.println();
           Day e1 = new Day(24, 7, 2008);
           Day e2 = new Day(24, 7, 2009);
           System.out.println("Days between "+e1+" and "+e2+"= "+e1.daysBetween(e2));
           
        }
    }
0
public enum Dni {
  PON,
  WT,
  SRO,
  CZW,
  PT,
  SOB,
  ND
}

A potem importujesz ten enum do pliku, gdzie chcesz go uzywac i uzywasz:
Dni.PON, Dni.WT, etc

lub:

                Dni t = Dni.PON;
		switch (t) {
		case PON : {
			break;
		}
		case WT : {
			break;
		}
		}

1 użytkowników online, w tym zalogowanych: 0, gości: 1