联盟计划程序,正确插入日期

时间:2018-06-05 14:01:49

标签: java

该程序存在一些问题。我是Java的新手,正在尝试制作联盟调度程序。我已达到用户可以输入所需的一些球队,预期联赛开始日期和结束日期的程度。一旦用户选择了结束日期,就会向用户建议一些轮次,因为这将是联盟需要持续的周数。目前,当联盟产生,日期打印完全,我的问题是我怎么能打印日期 - “圆1 05/06/2018”。另外,如何更改我的程序,以便接受奇数,类似于'再见'? 我为我对这个主题的不了解而道歉,我已经包含了我的代码片段和我的GUI图片,因此它提供了更多的背景。

非常感谢, 杰克enter image description here

       void cyclicRoll(int cycle[], int teams) {

    int tmp = cycle[1];

    for(int i=1;i<teams-1;i++) {

        int pr = cycle[i+1];

        cycle[i+1] = tmp;

        tmp = pr;

    }

    cycle[1] = tmp;

}

void scheduleTournament(int teams, int round) {

    if (((teams%2 != 0) && (round != teams - 1))||(teams <= 0))

        throw new IllegalArgumentException();

    int[] cycle = new int[teams];

    int n = teams /2;

    for (int i = 0; i < n; i++) {                                

        cycle[i] = i + 1;

        cycle[teams - i - 1] = cycle[i] + n;


    }                        

    Date startDate = (jXDatePicker1.getDate());
    Date endDate = (jXDatePicker2.getDate());
    LocalDate dates = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    LocalDate firstdate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

    DayOfWeek dayOfWeeek = dates.getDayOfWeek();

    LocalDate datee = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();  
    String listrep ="";
    String firstDateToPrint = firstdate.toString();

    while (!dates.equals(datee)) {
        jTextArea1.removeAll();
        if(dayOfWeeek == dayOfWeeek) {
            dates = dates.plusDays(7);

        }      
        String[] Itdates = {dates.toString()

            };

        for(String replacement : Itdates) {

            if ("".equals(listrep)) {
                listrep += replacement;
            } else {
                listrep +=  ", \n" + replacement ;
            }

        }
    }
    jTextArea1.append(firstDateToPrint + "\n");         
    jTextArea1.append(listrep);



    for(int d = 1; d <= round; d++) 
    {

        jTextArea1.append(String.format("Round %d\n",  d ));

        for (int i = 0; i < n; i++)
        {

            jTextArea1.append(String.format("team %d - team %d\n",cycle[i],cycle[teams - i - 1]));

        }

        //Roll the cycle keeping the first constant
        cyclicRoll(cycle,teams);        
    }
}
String ref;
String teams;
String rounds;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    jTextArea1.selectAll();
    jTextArea1.replaceSelection("");  
    teams = jTextField1.getText();
    int teamsToEnter = Integer.parseInt(teams);
    rounds = jTextField2.getText();
    int roundsToEnter = Integer.parseInt(rounds);
    ref = jTextField3.getText();
    jTextArea1.append("Ref "+ref + "\n");
    scheduleTournament(jTextField2,roundsToEnter);

}                                        

0 个答案:

没有答案