如何计算工厂的员工每天都在“随叫随到”?

时间:2012-08-12 19:38:45

标签: java io calendar scheduling

我正在研究我的第一个Java程序,它将用于实际目的而且我被卡住了 - 得到的输出不正确。

这是我正在尝试计算的问题:我工作的制造工厂每天24小时,每年363天(平安夜和圣诞节)以四天班次运营。每个工作人员连续工作4天12小时,然后休息4天。有四个工作人员,每个工作四天,然后休息四天,然后工作四个晚上,然后有四个晚上。船员和B船员彼此相反旋转,C船员和D船员彼此相反旋转。

当A Crew和B Crew正在工作时,C Crew和D Crew的成员随时待命,以防A或B船员上缺席。员工分为三类:高级操作员,初级操作员和复合器。在每个工作人员中,有四名高级操作员,三名初级操作员和2名复合操作员。对于四天轮换周期的前两天,三个高级运营商正在通话,而第四个未处于通话状态。在此期间未通话的高级运营商轮流:每次其他人都在通话时,其中一位未接听电话。在过去的两天里,三名初级运营商随叫随到。

对于高级雇员,前一个周期确定他们是否在白班或夜班的待命:如果不工作的工作人员一天工作,那么高级操作员将在前两天轮班,如果他们在上一个周期中一直工作,那么反之亦然。对于初级运营商而言,他们即将开始的周期决定了他们是在休息日两天还是在休息两天。

Compounders随叫随到第一天和第四天。无论是在白天还是晚上都在通话,其确定方式与运营商相同。

我的目标是用Java编写一个程序,用于计算每天和夜班的待命员工,并将结果输出到文本文件。我是一个业余爱好者,到目前为止只上过两个编程课程,所以我确信到目前为止我所写的内容效率远低于它。我只想弄清楚为什么输出不正确。我怀疑是我已经错误地计算了一个变量,或者我完全错过了一块拼图。请注意,为了该计划,一年的第一天是1月3日,因为第一天和第二天是上一年周期的一部分。

以下是我的代码。我删除了所有的getter和setter以适应分配的长度。我感谢任何可以提供的帮助。

    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();
}

}

1 个答案:

答案 0 :(得分:1)

这是一个适合初学者的优秀OOP项目。话虽如此,你需要以oop风格设计它。正确执行此操作的第一步,甚至接近使用多态来获得设计此程序的正确答案。

A)第一步是创建一个Employee类,然后创建子类Senior,Junior和Compound。这些类将包含有关最后一个动作(boolean oncall,boolean shift(day night)等)的跟踪信息。

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

这将是正确设计此程序的开始。一旦你达到这一点,如果你仍然再次被卡住,有人会帮助你进入下一阶段。

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