制作朱利安历法

时间:2018-02-16 21:54:30

标签: java calendar

我对Java有点新意。我在编写一个日历时遇到了一些麻烦,该日历接受了#34; Run Arguments"命令。我的导师提供了一个课程,给出了给定年份1月第一天的工作日。如果我理解正确,我们只需要知道1月何时开始知道其他月份开始的工作日。我需要一些帮助,因为我每个月只能在1月的第一天做。此外,我希望在他们到达最后一个工作日之后将这些日子带到一个新的线路上。提前谢谢大家。

import java.util.Calendar;
public class JulianCalendar
{
   public static void main(String[] args)
   {
      JulianDate JD = new JulianDate();
      int date = JD.toJulian(2018,1,1);
      int dayOfWeek = (date+1)%7;
      printCalendar();
   }
   public static void printCalendar()
   {
      JulianDate JD = new JulianDate();
      int date = JD.toJulian(2018,1,1);
      int dayOfWeek = (date+1)%7;
      int currentyear = Calendar.getInstance().get(Calendar.YEAR);
      for (int month=1; month <= 12; month++)
      {
         String monthString;
         //prints out months
         switch (month) 
         {
            case 1:  monthString = "January";
                     break;
            case 2:  monthString = "February";
                     break;
            case 3:  monthString = "March";
                     break;
            case 4:  monthString = "April";
                     break;
            case 5:  monthString = "May";
                     break;
            case 6:  monthString = "June";
                     break;
            case 7:  monthString = "July";
                     break;
            case 8:  monthString = "August";
                     break;
            case 9:  monthString = "September";
                     break;
            case 10: monthString = "October";
                     break;
            case 11: monthString = "November";
                     break;
            case 12: monthString = "December";
                     break;
            default: monthString = "Invalid month";
                     break;
          }
          System.out.printf("\n%17s\n",monthString);
          System.out.println("\nSun Mon Tue Wed Thu Fri Sat");
          System.out.print("  ");
          for(int i=0; i<dayOfWeek;i++)
          {
            System.out.print("    ");
          }
          int days=0;
          switch (month)
          {
            case 1:  days = 31;
                     break;
            case 2:  days = 28;
                     break;
            case 3:  days = 31;
                     break;
            case 4:  days = 30;
                     break;
            case 5:  days = 31;
                     break;
            case 6:  days = 30;
                     break;
            case 7:  days = 31;
                     break;
            case 8:  days = 31;
                     break;
            case 9:  days = 30;
                     break;
            case 10: days = 31;
                     break;
            case 11: days = 30;
                     break;
            case 12: days = 31;
                     break;
          }
          for (int i=1; i<=days; i++)
          {
            System.out.printf("%-4d",i);
          }
      }
   }
}

0 个答案:

没有答案