2012-11-28 72 views
-1

這是測試儀類,終端窗口只從行顯示的代表在終端窗口的java沒有出現

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類和Patient類

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; 

} 
      } 

Patient類

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

你試過調試嗎? –

+0

是的,我最近還添加了這些語句,但仍然沒有構建該項目? – Aaron

+0

仍然如此。 –

回答

1

很難檢驗一切(因爲是最好的,我可以告訴你定製DateTime類別不包括在這裏),但如果我冒險猜測,有沒有任何機會,窗口打印出所有這些語句,但有太多,你不能看到頂部的?

如果只有一些System.out.println的工作;嘗試註釋掉最後幾張照片,並檢查是否可以看到"Waiting position for patient3"之前的任何輸出。

+0

那麼,如果我打印我們的日期和時間課程,人們會發布downvote張貼太多的代碼行已經很少做了。我會嘗試讓你知道 – Aaron

+0

如果我註釋掉了一些代碼行,它仍然不顯示所有內容,但它確實改變了它顯示的內容。有些東西干擾我的代碼。 – Aaron

+0

我發現它出錯的地方,如果我在階段5(包括階段5)後刪除了所有內容,它會正常顯示。 – Aaron