这是测试人员类,终端窗口仅显示在行
System.out.println ("Waiting position for patient3: " + daylog.findWaitingPosition (patient3));
我在下面的代码中提到了(向下滚动一下以查看我的文字)。它没有显示任何东西,任何人都知道为什么?
import java.text.DecimalFormat;
public class DayLogTest
{
public static void main (String[] args)
{
DayLog today = new DayLog (11,12,1992);
doTest(today);
}
private static void doTest (DayLog daylog)
{
Patient patient1 = new Patient(1111, "aaaa", "aaaa", 11,11,1991);
Patient patient2 = new Patient(2222, "bbbb", "bbbb", 9,12,1992);
Patient patient3 = new Patient(3333, "cccc", "cccc", 8,7,1941);
Patient patient4 = new Patient(4444, "dddd", "dddd", 4,5,1851);
Patient patient5 = new Patient(5555, "eeee", "eeee", 1,1,1231);
System.out.println ("Test 1");
System.out.println ("------------------------------------------------------------");
System.out.println ("Phase 1: Adding Patients (patient1, patient2, patient3) ");
daylog.addPatient (patient1, 12,30);
daylog.addPatient (patient2, 12,40);
daylog.addPatient (patient3, 8,40);
System.out.println ("Number of Patients Arrived: " + daylog.getArrived());
System.out.println ("Number of Patients Waiting: " + daylog.getNumberWaiting());
System.out.println ("Waiting position for patient1: " + daylog.findWaitingPosition (patient1));
System.out.println ("Waiting position for patient2: " + daylog.findWaitingPosition (patient2));
System.out.println ("Waiting position for patient3: " + daylog.findWaitingPosition (patient3));
System.out.println ("------------------------------------------------------------");
System.out.println ("Treating patient1");
daylog.treatPatient (patient1, 15, 30);
System.out.println ("Number of Patients Waiting: " + daylog.getNumberWaiting());
System.out.println ("Waiting position for patient2: " + daylog.findWaitingPosition (patient2));
DOES NOT PRINT ANYTHING ABOVE HERE IN TERMINAL WINDOW
DOES NOT PRINT ANYTHING ABOVE HERE IN TERMINAL WINDOW
DOES NOT PRINT ANYTHING ABOVE HERE IN TERMINAL WINDOW
System.out.println ("Waiting position for patient3: " + daylog.findWaitingPosition (patient3));
System.out.println ("------------------------------------------------------------");
System.out.println ("Phase 2: Adding patient4 and patient 5");
daylog.addPatient (patient4, 5,25);
daylog.addPatient (patient5, 16,24);
System.out.println ("Number of Patients Arrived: " + daylog.getArrived());
System.out.println ("Number of Patients Waiting: " + daylog.getNumberWaiting());
System.out.println ("Waiting position for patient2: " + daylog.findWaitingPosition (patient2));
System.out.println ("Waiting position for patient3: " + daylog.findWaitingPosition (patient3));
System.out.println ("Waiting position for patient4: " + daylog.findWaitingPosition (patient4));
System.out.println ("Waiting position for patient5: " + daylog.findWaitingPosition (patient5));
System.out.println ("------------------------------------------------------------");
System.out.println ("Treating patient 3 and 5");
daylog.treatPatient (patient3, 11,40);
daylog.treatPatient (patient5, 19,24);
System.out.println ("Number of Patients Arrived: " + daylog.getArrived());
System.out.println ("Number of Patients Waiting: " + daylog.getNumberWaiting());
System.out.println ("Waiting position for patient2: " + daylog.findWaitingPosition (patient2));
System.out.println ("Waiting position for patient4: " + daylog.findWaitingPosition (patient4));
System.out.println ("------------------------------------------------------------");
System.out.println ("Phase 3: printReport method");
daylog.printReport();
System.out.println ("------------------------------------------------------------");
System.out.println ("Phase 4: printWaitingList Method");
daylog.printWaitingList();
System.out.println ("------------------------------------------------------------");
System.out.println ("Phase 5: getAverageWaitingTime Method");
System.out.println ("I have designed the test to be 3 hours average so far, which is 180 minutes");
DecimalFormat fmt = new DecimalFormat ("");
System.out.println ("Average waiting time: " + fmt.format(daylog.getAverageWaitingTime()) + " minutes");
System.out.println ("------------------------------------------------------------");
System.out.println ("Phase 6: Adding patient2");
daylog.treatPatient (patient2, 20, 40);
System.out.println ("Number of Patients Arrived: " + daylog.getArrived());
System.out.println ("Number of Patients Waiting: " + daylog.getNumberWaiting());
System.out.println ("Waiting position for patient2: " + daylog.findWaitingPosition (patient1));
System.out.println ("Waiting position for patient2: " + daylog.findWaitingPosition (patient2));
System.out.println ("Waiting position for patient3: " + daylog.findWaitingPosition (patient3));
System.out.println ("Waiting position for patient4: " + daylog.findWaitingPosition (patient4));
System.out.println ("Waiting position for patient5: " + daylog.findWaitingPosition (patient5));
}
}
如需要参考,DayLog课程和患者课程
public class DayLog
{
private Date logDate;
private int noOfArrivals = 0;
//Number of waiting patients, different from number of arrived.
private int noOfWaiting = 0;
//Number of patients being treated
private int noOfTreated = 0;
//Sets the size of the waitinglist and treatmentlist arrays
private int waitingListCapacity = 100;
private int treatmentListCapacity = 100;
//Waitlist position for the method findWaitingPosition which is one more than the index.
private int waitlistPosition;
private Patient[] waitingList;
private Patient[] treatmentList;
public DayLog (int day, int month, int year)
{
logDate = new Date (day, month, year);
waitingList = new Patient[waitingListCapacity];
treatmentList = new Patient[treatmentListCapacity];
}
public void addPatient (Patient patient, int hours, int minutes)
{
patient.setArrivalTime (hours, minutes);
noOfArrivals++;
for (int i = 0; i <= waitingList.length-1; i++)
{
if ( waitingList[i] == null )
{
waitingList[i] = patient;
noOfWaiting++;
return;
}
}
}
public int getArrived ()
{
return noOfArrivals;
}
public int getNumberWaiting ()
{
return noOfWaiting;
}
public int findWaitingPosition (Patient patient)
{
for ( int i=0; i <= waitingList.length-1; i++)
{
if ( waitingList[i] == patient )
{
waitlistPosition = i+1;
return waitlistPosition;
}
}
return -1;
}
public void treatPatient (Patient patient, int hours, int minutes)
{
for (int i = 0; i <= waitingList.length-1; i++)
{
if (waitingList[i] == patient)
{
patient.setTreatmentStart (hours, minutes);
treatmentList[noOfTreated] = patient;
noOfTreated++;
for (int j=i; j < noOfWaiting-1; j++ )
{
waitingList[j] = waitingList[j+1];
}
waitingList[noOfWaiting-1] = null;
noOfWaiting--;
}
}
}
public void printReport ()
{
System.out.println ("Number of patients arrived: " + noOfArrivals);
System.out.println ("Number of patients waiting: " + noOfWaiting );
System.out.println ("Number of being treated: " + noOfTreated);
}
public void printWaitingList ()
{
for (int i = 0; i <= waitingList.length-1; i++)
{
if ( waitingList[i] == null )
{
}
else
{
waitingList[i].getAsString();
}
}
}
public void printTreatmentList ()
{
for (int i = 0; i <= treatmentList.length-1; i++)
{
if ( treatmentList[i] == null )
{
}
else
{
treatmentList[i].getAsString();
}
}
}
public double getAverageWaitingTime ()
{
int sum = 0;
int count = 0;
double averageWaitingTime;
for (int i = 0; i <= treatmentList.length-1; i++)
{
if ( treatmentList[i] == null )
{
}
else
{
sum += treatmentList[i].getWaitingTime();
count++;
}
}
averageWaitingTime = (sum / count);
return averageWaitingTime;
}
}
患者类
public class Patient
{
private int patientRefNo;
private String patientName;
private String patientGp;
private Date patientBirthday;
private Time patientArrivalTime;
private Time patientTreatmentTime;
public Patient (int refNo, String name, String gp, int day, int month, int year)
{
patientRefNo = refNo;
patientName = name;
patientGp = gp;
patientBirthday = new Date(day, month, year);
patientArrivalTime = null;
patientTreatmentTime = null;
}
protected void setArrivalTime (int hours, int minutes)
{
patientArrivalTime = new Time (hours, minutes);
}
protected void setTreatmentStart (int hours, int minutes)
{
patientTreatmentTime = new Time (hours, minutes);
}
public int getPatientNo ()
{
return patientRefNo;
}
public String getGPName ()
{
return patientGp;
}
public Date getDOB ()
{
return patientBirthday;
}
public int getWaitingTime ()
{
if ( patientArrivalTime == null || patientTreatmentTime == null )
{
return -1;
}
else
{
return patientTreatmentTime.getElapsedTime (patientArrivalTime);
}
}
public String getAsString ()
{
System.out.println ("Patient Name: " + patientName);
System.out.println ("Patient Reference Number: " + patientRefNo);
System.out.println ("Patient Family Doctor: " + patientGp);
System.out.println ("Patient Birthday: " + patientBirthday.getAsString());
if ( patientArrivalTime == null )
{
System.out.println ("Patient Arrival Time: this patient has not arrived yet");
}
else
{
System.out.println ("Patient Arrival Time: " + patientArrivalTime.getAsString());
}
if ( patientTreatmentTime == null )
{
System.out.println ("Patient Treatment Time: this patient has not been treated yet");
}
else
{
System.out.println ("Patient Arrival Time: " + patientTreatmentTime.getAsString());
}
return "";
}
}
答案 0 :(得分:1)
很难对所有内容进行测试(因为我可以告诉您,此处未包含自定义Date
和Time
类),但如果我冒险猜测,是否有可能窗口 打印出所有这些陈述,但有很多东西你不能看到最好的陈述?
如果System.out.println
中只有一部分有效,那就很奇怪了。尝试评论一些最后的打印件,并检查是否可以看到"Waiting position for patient3"
之前的任何输出。