我正在开发我的第一个Java程序,该程序将用于实际目的,但我遇到了麻烦-得到了不正确的输出。

这是我要计算的问题:我工作的制造厂每天四班制,一年363天(圣诞节前夕和圣诞节后)每天24/7营业。每个工作人员连续12个工作日(白天或夜晚)工作4个小时,然后休息4天。有四个工作人员,每个工作四天,然后休息四天,然后工作四个晚上,然后休息四晚。 A机组和B机组彼此相对旋转,C机组和D机组彼此相对旋转。

当A Crew和B Crew工作时,C Arew和D Crew的成员正在召集,以防A或B Crew上的人员缺席。员工分为三类:高级操作员,初级操作员和复合人员。每位机组人员中有四名高级操作员,三名初级操作员和两名复合人员。在为期四天的轮换周期的前两天,三名高级操作员正在值班,而第四名不在话务员位置。在此期间未处于待命状态的高级操作员轮换:每次其他人待命时,一个不在呼叫中。在最后两天,三名初级操作员正在待命。

对于高级员工,上一个周期确定他们是白天轮班还是夜间轮班待命:如果不工作的员工已经在上班,那么高级操作员会在头两天轮班待命,反之亦然如果他们在上一个周期内晚上工作。对于初级操作员,他们将要开始的周期决定了他们在后两天的休息日是白天还是白天。

复合工在第一天和第四天休息。无论是白天还是晚上都在通话中,其确定方式与操作员相同。

我的目标是用Java编写一个程序,该程序可以计算出白天和黑夜每天要上班的员工,并将结果输出到文本文件中。我是一个业余爱好者,到目前为止只参加了两个编程课程,因此可以肯定,到目前为止我写的东西效率远不如预期。我只是想弄清楚为什么输出不正确。我的怀疑是我或者错误地计算了一个变量,或者我完全错过了一个难题。请注意,计划的第一天是1月3日,因为第一天和第二天是上一年周期的一部分。

下面是我的代码。我删除了所有吸气剂和二传手以适应分配的长度。我感谢可以提供的所有帮助。

    import java.io.File;
    import java.io.PrintWriter;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Scanner;

    public class OnCallAug812 {
Calendar cal1 = Calendar.getInstance();
private double cycleDay = ((cal1.get(Calendar.DAY_OF_YEAR) - 3)) % 16;
private double dayOfCycle = cycleDay % 4;
// number of days into current rotation ( 0 =4, 1=1, 2=2, 3=3)
private int cycleRotation = (int) (cycleDay / 4);
// number of current rotation (4 per cycle)
private int cycleOfYear = ((cal1.get(Calendar.DAY_OF_YEAR) - 3) / 16);
private int onCallCycle = cycleOfYear % 4;


// A crew operators: 4 Senior
private int a1S = 0;
private int a2S = 1;
private int a3S = 2;
private int a4S = 3;

// variables for A crew names
private String a1;
private String a2;
private String a3;
private String a4;

// A Crew Junior Operators represented by one variable b/c
// all are on call or not on call at same time

private int aJr;

// A crew junior operator names
private String aJr1;
private String aJr2;
private String aJr3;

// B crew operators: 4 Senior
private int b1S = 0;
private int b2S = 1;
private int b3S = 2;
private int b4S = 3;

// B crew operator names
private String b1;
private String b2;
private String b3;
private String b4;

// B Crew Junior Operators represented by one variable b/c
// all are on call or not on call at same time

private int bJr;

// B crew operator junior names
private String bJr1;
private String bJr2;
private String bJr3;

// C crew operators: 4 Senior
private int c1S = 0;
private int c2S = 1;
private int c3S = 2;
private int c4S = 3;

// C operator senior names
private String c1;
private String c2;
private String c3;
private String c4;

// C Crew Junior Operators represented by one variable b/c
// all are on call or not on call at same time

private int cJr;

// C crew junior operator names
private String cJr1;
private String cJr2;
private String cJr3;

// D crew operators: 4 Senior
private int d1S = 0;
private int d2S = 1;
private int d3S = 2;
private int d4S = 3;

// d crew senior names
private String d1;
private String d2;
private String d3;
private String d4;

// D Crew Junior Operators represented by one variable b/c
// all are on call or not on call at same time

private int dJr;

// D crew junior operator names
private String dJr1;
private String dJr2;
private String dJr3;

// Call status for each A Crew employee--set to 0,1, or 2
// 0 = on call day shift
// 1 = on call night shift
// 2 = off call
private int a1SCallStat = -1;
private int a2SCallStat = -1;
private int a3SCallStat = -1;
private int a4SCallStat = -1;
private int aJrCallStat = -1;

// Call status for each B Crew employee--set to 0,1, or 2
private int b1SCallStat = -1;
private int b2SCallStat = -1;
private int b3SCallStat = -1;
private int b4SCallStat = -1;
private int bJrCallStat = -1;

// Call status for each C Crew employee--set to 0,1, or 2
private int c1SCallStat = -1;
private int c2SCallStat = -1;
private int c3SCallStat = -1;
private int c4SCallStat = -1;
private int cJrCallStat = -1;

// Call status for each D Crew employee--set to 0,1, or 2
private int d1SCallStat = -1;
private int d2SCallStat = -1;
private int d3SCallStat = -1;
private int d4SCallStat = -1;
private int dJrCallStat = -1;

// Call status for each crew's pelletizer operators (both on or both off)

private int aP;
private int bP;
private int cP;
private int dP;

private String aP1;
private String aP2;
private String bP1;
private String bP2;
private String cP1;
private String cP2;
private String dP1;
private String dP2;

private int aPCallStat = -1;
private int bPCallStat = -1;
private int cPCallStat = -1;
private int dPCallStat = -1;

public int determineCall(double onCallCycle, int crewNumber) {
    double aNumber = (crewNumber + onCallCycle) % 7;
    if (aNumber <= 2) {
        return 0;
    } else if (aNumber >= 3 && aNumber < 6) {
        return 1;
    } else if (aNumber == 6) {
        return 2;
    } else
        return -1;
}

public int determineCallJr(double onCallCycle, int crewNumber){
    double aNumber = (crewNumber + onCallCycle) % 7;
    if (aNumber <= 3) {
        return 0;
    } else if (aNumber >= 4 && aNumber <= 6) {
        return 1;
    } else
        return -1;
}

public int determineCallP(double onCallCycle, int crewNumber){
    double aNumber = (crewNumber + onCallCycle) % 7;
    if (aNumber <= 3) {
        return 0;
    } else if (aNumber >= 4 && aNumber <= 6) {
        return 1;
    } else
        return -1;
}

public void calcCall(OnCallAug812 aug1) {
    // Senior employees on call checks
    if ((aug1.cycleRotation == 0)
            && ((aug1.dayOfCycle == 1) || (aug1.dayOfCycle == 0))) {
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC1S()) == 0) {
            aug1.setC1SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC1S()) == 1) {
            aug1.setC1SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC1S()) == 2) {
            aug1.setC1SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC2S()) == 0) {
            aug1.setC2SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC2S()) == 1) {
            aug1.setC2SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC2S()) == 2) {
            aug1.setC2SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC3S()) == 0) {
            aug1.setC3SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC3S()) == 1) {
            aug1.setC3SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC3S()) == 2) {
            aug1.setC3SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC4S()) == 0) {
            aug1.setC4SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC4S()) == 1) {
            aug1.setC4SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC4S()) == 2) {
            aug1.setC4SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD1S()) == 0) {
            aug1.setD1SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD1S()) == 1) {
            aug1.setD1SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD1S()) == 2) {
            aug1.setD1SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD2S()) == 0) {
            aug1.setD2SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD2S()) == 1) {
            aug1.setD2SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD2S()) == 2) {
            aug1.setD2SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD3S()) == 0) {
            aug1.setD3SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD3S()) == 1) {
            aug1.setD3SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD3S()) == 2) {
            aug1.setD3SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD4S()) == 0) {
            aug1.setD4SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD4S()) == 1) {
            aug1.setD4SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD4S()) == 2) {
            aug1.setD4SCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 1)
            && ((aug1.dayOfCycle == 1) || (aug1.dayOfCycle == 0))) {
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA1S()) == 0) {
            aug1.setA1SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA1S()) == 1) {
            aug1.setA1SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA1S()) == 2) {
            aug1.setA1SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA2S()) == 0) {
            aug1.setA2SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA2S()) == 1) {
            aug1.setA2SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA2S()) == 2) {
            aug1.setA2SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA3S()) == 0) {
            aug1.setA3SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA3S()) == 1) {
            aug1.setA3SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA3S()) == 2) {
            aug1.setA3SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA4S()) == 0) {
            aug1.setA4SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA4S()) == 1) {
            aug1.setA4SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA4S()) == 2) {
            aug1.setA4SCallStat(2);
        }

        // b crew second rotation
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB1S()) == 0) {
            aug1.setB1SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB1S()) == 1) {
            aug1.setB1SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB1S()) == 2) {
            aug1.setB1SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB2S()) == 0) {
            aug1.setB2SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB2S()) == 1) {
            aug1.setB2SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB2S()) == 2) {
            aug1.setB2SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB3S()) == 0) {
            aug1.setB3SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB3S()) == 1) {
            aug1.setB3SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB3S()) == 2) {
            aug1.setB3SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB4S()) == 0) {
            aug1.setB4SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB4S()) == 1) {
            aug1.setB4SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB4S()) == 2) {
            aug1.setB4SCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 2)
            && ((aug1.dayOfCycle == 1) || (aug1.dayOfCycle == 0))) {
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC1S()) == 0) {
            aug1.setC1SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC1S()) == 1) {
            aug1.setC1SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC1S()) == 2) {
            aug1.setC1SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC2S()) == 0) {
            aug1.setC2SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC2S()) == 1) {
            aug1.setC2SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC2S()) == 2) {
            aug1.setC2SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC3S()) == 0) {
            aug1.setC3SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC3S()) == 1) {
            aug1.setC3SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC3S()) == 2) {
            aug1.setC3SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC4S()) == 0) {
            aug1.setC4SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC4S()) == 1) {
            aug1.setC4SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getC4S()) == 2) {
            aug1.setC4SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD1S()) == 0) {
            aug1.setD1SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD1S()) == 1) {
            aug1.setD1SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD1S()) == 2) {
            aug1.setD1SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD2S()) == 0) {
            aug1.setD2SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD2S()) == 1) {
            aug1.setD2SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD2S()) == 2) {
            aug1.setD2SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD3S()) == 0) {
            aug1.setD3SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD3S()) == 1) {
            aug1.setD3SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD3S()) == 2) {
            aug1.setD3SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD4S()) == 0) {
            aug1.setD4SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD4S()) == 1) {
            aug1.setD4SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getD4S()) == 2) {
            aug1.setD4SCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 3)
            && ((aug1.dayOfCycle == 1) || (aug1.dayOfCycle == 0))) {
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA1S()) == 0) {
            aug1.setA1SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA1S()) == 1) {
            aug1.setA1SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA1S()) == 2) {
            aug1.setA1SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA2S()) == 0) {
            aug1.setA2SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA2S()) == 1) {
            aug1.setA2SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA2S()) == 2) {
            aug1.setA2SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA3S()) == 0) {
            aug1.setA3SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA3S()) == 1) {
            aug1.setA3SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA3S()) == 2) {
            aug1.setA3SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA4S()) == 0) {
            aug1.setA4SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA4S()) == 1) {
            aug1.setA4SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getA4S()) == 2) {
            aug1.setA4SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB1S()) == 0) {
            aug1.setB1SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB1S()) == 1) {
            aug1.setB1SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB1S()) == 2) {
            aug1.setB1SCallStat(2);
        }
        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB2S()) == 0) {
            aug1.setB2SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB2S()) == 1) {
            aug1.setB2SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB2S()) == 2) {
            aug1.setB2SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB3S()) == 0) {
            aug1.setB3SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB3S()) == 1) {
            aug1.setB3SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB3S()) == 2) {
            aug1.setB3SCallStat(2);
        }

        if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB4S()) == 0) {
            aug1.setB4SCallStat(0);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB4S()) == 1) {
            aug1.setB4SCallStat(1);
        } else if (aug1.determineCall(aug1.getOnCallCycle(), aug1.getB4S()) == 2) {
            aug1.setB4SCallStat(2);
        }
    }

    // Junior Extruder Operators
    if ((aug1.cycleRotation == 0)
            && ((aug1.dayOfCycle == 3) || (aug1.dayOfCycle == 2))) {
        if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getcJr()) == 0) {
            aug1.setcJrCallStat(0);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getcJr()) == 1) {
            aug1.setcJrCallStat(1);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getcJr()) == 2) {
            aug1.setcJrCallStat(2);
        }
        if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getdJr()) == 0) {
            aug1.setDjrCallStat(1);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getdJr()) == 1) {
            aug1.setDjrCallStat(0);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getdJr()) == 2) {
            aug1.setDjrCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 1)
            && ((aug1.dayOfCycle == 3) || (aug1.dayOfCycle == 2))) {
        if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getaJr()) == 0) {
            aug1.setaJrCallStat(0);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getaJr()) == 1) {
            aug1.setaJrCallStat(1);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getaJr()) == 2) {
            aug1.setaJrCallStat(2);
        }
        if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getbJr()) == 0) {
            aug1.setbJrCallStat(1);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getbJr()) == 1) {
            aug1.setbJrCallStat(0);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getbJr()) == 2) {
            aug1.setbJrCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 2)
            && ((aug1.dayOfCycle == 3) || (aug1.dayOfCycle == 2))) {
        if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getcJr()) == 0) {
            aug1.setcJrCallStat(0);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getcJr()) == 1) {
            aug1.setcJrCallStat(1);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getcJr()) == 2) {
            aug1.setcJrCallStat(2);
        }
        if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getdJr()) == 0) {
            aug1.setDjrCallStat(1);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getdJr()) == 1) {
            aug1.setDjrCallStat(0);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getdJr()) == 2) {
            aug1.setDjrCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 3)
            && ((aug1.dayOfCycle == 3) || (aug1.dayOfCycle == 2))) {
        if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getaJr()) == 0) {
            aug1.setaJrCallStat(0);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getaJr()) == 1) {
            aug1.setaJrCallStat(1);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getaJr()) == 2) {
            aug1.setaJrCallStat(2);
        }
        if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getbJr()) == 0) {
            aug1.setbJrCallStat(1);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getbJr()) == 1) {
            aug1.setbJrCallStat(0);
        } else if (aug1.determineCallJr(aug1.getOnCallCycle(), aug1.getbJr()) == 2) {
            aug1.setbJrCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 0)
            && ((aug1.dayOfCycle == 3) || (aug1.dayOfCycle == 0))) {
        if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getcP()) == 0) {
            aug1.setcPCallStat(0);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getcP()) == 1) {
            aug1.setcPCallStat(1);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getcP()) == 2) {
            aug1.setcPCallStat(2);
        }
        if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getdP()) == 0) {
            aug1.setdPCallStat(1);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getdP()) == 1) {
            aug1.setdPCallStat(0);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getdP()) == 2) {
            aug1.setdPCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 1)
            && ((aug1.dayOfCycle == 3) || (aug1.dayOfCycle == 0))) {
        if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getaP()) == 0) {
            aug1.setaPCallStat(0);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getaP()) == 1) {
            aug1.setaPCallStat(1);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getaP()) == 2) {
            aug1.setaPCallStat(2);
        }

        if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getbP()) == 0) {
            aug1.setbPCallStat(1);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getbP()) == 1) {
            aug1.setbPCallStat(0);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getbP()) == 2) {
            aug1.setbPCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 2)
            && ((aug1.dayOfCycle == 3) || (aug1.dayOfCycle == 0))) {
        if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getcP()) == 0) {
            aug1.setcPCallStat(1);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getcP()) == 1) {
            aug1.setcPCallStat(0);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getcP()) == 2) {
            aug1.setcPCallStat(2);
        }
        if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getdP()) == 0) {
            aug1.setdPCallStat(0);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getdP()) == 1) {
            aug1.setdPCallStat(1);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getdP()) == 2) {
            aug1.setdPCallStat(2);
        }
    }

    if ((aug1.cycleRotation == 3)
            && ((aug1.dayOfCycle == 3) || (aug1.dayOfCycle == 0))) {
        if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getaP()) == 0) {
            aug1.setaPCallStat(1);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getaP()) == 1) {
            aug1.setaPCallStat(0);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getaP()) == 2) {
            aug1.setaPCallStat(2);
        }
        if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getbP()) == 0) {
            aug1.setbPCallStat(0);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getbP()) == 1) {
            aug1.setbPCallStat(1);
        } else if (aug1.determineCallP(aug1.getOnCallCycle(), aug1.getbP()) == 2) {
            aug1.setbPCallStat(2);
        }
    }
}

private String readFile(String pathname) throws Exception {

    File file = new File(pathname);
    StringBuilder fileContents = new StringBuilder((int) file.length());
    Scanner scanner = new Scanner(file);
    String lineSeparator = System.getProperty("line.separator");

    try {
        while (scanner.hasNextLine()) {
            fileContents.append(scanner.nextLine() + lineSeparator);
        }
        return fileContents.toString();
    } finally {
        scanner.close();
    }
}

public void check0(PrintWriter output2, int callStat, String name) {
    if (callStat == 0) {
        output2.print(name);
        output2.println();
    }
}

public void check1(PrintWriter output2, int callStat, String name) {
    if (callStat == 1) {
        output2.print(name);
        output2.println();
    }
}

public void addDate(OnCallAug812 aug1) {
    cal1.add(Calendar.DATE, 1);
    aug1.cycleDay = ((cal1.get(Calendar.DAY_OF_YEAR) - 3)) % 16;
    aug1.dayOfCycle = cycleDay % 4;
    // number of days into current rotation ( 0 =4, 1=1, 2=2, 3=3)
    aug1.cycleRotation = (int) (cycleDay / 4);
    // number of current rotation (4 per cycle)
    aug1.cycleOfYear = ((cal1.get(Calendar.DAY_OF_YEAR) - 2) / 16);
    aug1.onCallCycle = cycleOfYear % 4;
}

public static void main(String[] args) throws Exception {
    OnCallAug812 aug1 = new OnCallAug812();
    aug1.calcCall(aug1);
    System.out.print("Day of 16 day rotation(0 to 15): ");
    System.out.println(aug1.cycleDay);
    System.out.print("Day of 4 day cycle (0 to 3): ");
    System.out.println(aug1.dayOfCycle);
    System.out.print("Cycle of 16 day rotation (0 to 3): ");
    System.out.println(aug1.cycleRotation);
    System.out.print("16 day cycle number (0 to 22): ");
    System.out.println(aug1.cycleOfYear);
    System.out.print("On Call Cycle Number(0 to 6 then repeat): ");
    System.out.println(aug1.onCallCycle);
}

public OnCallAug812() {
    super();
}


}

最佳答案

对于初学者来说,这是一个很好的OOP项目。话虽这么说,您需要以oop风格进行设计。正确执行此操作的第一步,甚至接近获得使用多态设计此程序的正确答案。

A)第一步是创建一个Employee类,然后创建Senior,Junior和Compound子类。这些类将包含有关该雇员最后动作的跟踪信息(布尔值调用,布尔值转换(白天)等)

B)下一步将是弄清楚如何创建一个可能是另一类的工作人员。然后,乘务员班级可以跟踪因素,例如最后工作的人,他们工作的班次,最后没有待命的人等。班级将包含员工组。

这将是正确设计该程序的开始。一旦到达这一点,如果您仍然遇到问题,就会有人帮助您进入下一阶段。

如果您需要执行此操作的示例,则可以查看我的ProGauge项目,该项目使用不同类型的设备执行类似的操作,例如:http://www.behance.net/gallery/ProGauge-Project-in-java-JSON-Data-management/4668415或在网上找到一些Java多态性实例!

09-04 22:49