我想根据用户给出的日期返回患者的医生列表。但每次运行该方法时,它都会返回所有医生的列表,而不是被过滤。搜索病人使用方法过滤arraylist
public boolean searchDatesForDoc(Date date){
for(Date i : datesOfVisit)
{
if(i.equals(date))
{
return true;
}
}
return false;
}
我已经初始化2例即patient1和患者2日期
守则主要
public void printDoctorsWithPatientsOnDate() throws ParseException
{
ArrayList<String> docs = new ArrayList();
System.out.print("Enter the date(mm-dd-yyyy): ");
Date dt = new SimpleDateFormat("MM-dd-yyyy").parse(sc.nextLine());
docs = app.getDoctorsWithPatientsOnDate(dt);
for(String i : docs)
{
System.out.println(i);
}
}
方法过滤
public ArrayList<String> getDoctorsWithPatientsOnDate(Date date)
{
ArrayList<String> doctors = new ArrayList();
for(Patient i : patientList)
{
if(i.searchDatesForDoc(date) == true);
{
doctors.add(i.getDoctorName());
}
}
return doctors;
}
方法。患者1的医生被命名为dr.lee,患者2的医生被命名为dr.james。首先,我为患者1输入以下信息,并且我没有任何(现在)留下患者2。
Enter the Patient's name: patient1
Enter the assessment: alz
Enter the date of Visit(mm-dd-yyyy): 10-02-2010
问题出现在我拿到医生名单时。即使日期错误,它仍会继续打印列表上的每位医生。
Enter the date(mm-dd-yyyy): 11-20-2012
dr.lim
dr.james
'if(i.serachDatesForDoc(date)== true)' - 你不需要'== true'。由于'searchDatesForDoc'返回一个布尔值,你可以使用它作为条件。我怀疑这是你的问题 - 我不明白为什么会这样 - 但它可能有帮助。 – MrB
@MrB我尝试了你说的话,但没有发生任何事。我仍然有同样的问题.. – ZeroStream