0

うるう年は気にしたくないけど、自分の土台が正しいか心配です。

javax.swing.Spring をインポートします。

public class Date 
{

    /**
     * A variable to hold the day value
     */
    private int day;

    /**
     * A variable to hold the month value
     */
    private int month;

    /**
     * A variable to hold the year value
     */
    private int year;

    /**
     * the date in the form m/d/yyyy
     */
    private String stringDate;

    /**
     * To figure out which month it is
     */
    private boolean isThirtyDays, isThirtyOneDays, isTwentyEightDays;

    /**
     * advances the date by one day based on the month
     */
    private void advance()
    {

        if(month == 9 || month == 4 || month == 6 || month == 11)
        {
            if(day == 30)
            {
                month++;
                day = 1;
            }

            else
                day++;
        }

        if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8
                || month == 10 || month == 12)
        {
            if(day == 31)

            {
                month++;
                day = 1;

                if(month == 12)

                {
                    month = 1;
                    day = 1;
                    year++;
                }
            }

            else
                day++;
        }

        if(month == 2)

        {
            if(day == 28)

            {
                month++;
                day = 1;
            }

            else
                day++;
        }
    }

    /**
     * Takes the year, month and day and displays it as m/d/yyyy
     * Before it does it though, it changes all the ints to strings 
     */
    private String toString(int yearString, int monthString, int dayString)
    {

        stringDate = (Integer.toString(monthString) + "/" + Integer.toString(dayString)
                + "/" + Integer.toString(yearString));

        return stringDate;
    }

}

私が疑問に思っているのは、すべて || です。ステートメントが実際に正しいか、または必要な作業がはるかに少ない方法があるかどうか。私はJavaにもかなり慣れていないので、Eclipse環境でこれをテキスト化する最良の方法は何だろうと思っていました。

4

1 に答える 1

0

カレンダーを使用しない理由

Calendar time = Calendar.getInstance();

time.add(Calendar.DAY,+1)

于 2013-09-05T20:27:09.927 に答える