我的业务是这样的:
   小弟我正在开发一个教务管理系统,其中有一个排课的功能:需要实现根据,具体的开课时间,每星期上课的时间和总的课次生成具体的上课日期。比如: 开课日期是星期三,是6月1日,每周上课是
             周一8:00-10:00
             周三8:00-10:00
             周六10:00-12:00
一共是10次课,生成具体的班级上课时间是
             6月1日8:00-10:00第一次课
             6月4日10:00-12:00第二次课
             6月6日8:00-10:00 第三次课
             .........
             .........
请教高手,如何实现?感激万分

解决方案 »

  1.   

    package com.test;import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.List;public class Test5 {  public static void main(String[] args) throws ParseException {    List<Lesson> list = new ArrayList<Lesson>();    // 1表示星期日,7表示星期六
        Lesson less1 = new Lesson(2, "8:00——10:00");
        Lesson less2 = new Lesson(4, "10:00——11:00");
        Lesson less3 = new Lesson(7, "10:00——12:00");
        list.add(less1);
        list.add(less2);
        list.add(less3);
        // list最好能排序    // 总的上课次数
        int total = 10;
        // 开课日期,并非要与日期对应,可以是开课星的星期一或这个星的任何一天。
        String startDate = "2007-07-01";  
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
        Date d = s.parse(startDate);
        teachList(list, total, d);
      }  public static void teachList(List<Lesson> list, int total, Date startDate) {
        Calendar c = Calendar.getInstance();
        c.setTime(startDate);
        c.set(Calendar.DAY_OF_WEEK, list.get(0).getWeek());
        if (c.getTimeInMillis() < startDate.getTime()) {
          c.add(Calendar.DATE, 7);
        }
        StringBuffer sb = new StringBuffer();
        int i = 1;
        while (i <= total) {
          for (Lesson less : list) {
            c.set(Calendar.DAY_OF_WEEK, less.getWeek());
            SimpleDateFormat s = new SimpleDateFormat("yyyy年MM月dd日 E");
            sb.append("第").append(i).append("次课 ");
            sb.append(s.format(c.getTime())).append(" ");
            sb.append(less.getTime()).append("\n");
            ++i;
            if (i > total) {
              break;
            }
          }
          c.add(Calendar.DATE, 7);
        }
        sb.trimToSize();
        System.out.println(sb.toString());
      }
    }class Lesson {
      private int week;  private String time;  public Lesson() {
      }
      public Lesson(int week, String time) {
        this.week = week;
        this.time = time;
      }
      public String getTime() {
        return time;
      }
      public void setTime(String time) {
        this.time = time;
      }
      public int getWeek() {
        return week;
      }
      public void setWeek(int week) {
        this.week = week;
      }
    }
      

  2.   

    bao110908,谢谢你,不知你是否在北京