file io .contains变量没有输出

时间:2015-10-23 00:17:56

标签: java

首先,抱歉格式化,我是所有这一切的菜鸟。我试图根据患者姓名,日期,时间和医生阅读医生预约清单。我的任务是阅读文件并显示该医生的所有约会。我们之前一周或两周在课堂上做了类似的任务,所以我试图将我的工作作为基础,但它不起作用。我没有得到任何输出,我不知道为什么。如果有人能查看我的代码,那就太棒了,谢谢!

import java.util.Scanner;
import java.io.*;

public class DocList

{

  public static void main(String [] args) throws IOException

  {

    File file = new File("appts.txt");

    Scanner infile = new Scanner(file);
    Scanner kb = new Scanner(System.in);

    String name;
    String month;
    String day;
    String year;
    String militaryTime="";
    String doctor;
    long date=0;
    String nameDoc;
    System.out.println("enter doctor name: ");
    nameDoc = kb.nextLine();
    int sYear=0;
    int sMonth=0;
    int sDay=0;

    while(infile.hasNext())
    {
      name = infile.next();
      month = infile.next();
      day = infile.next();
      year = infile.next();
      militaryTime=infile.next();
      doctor=infile.nextLine();
      sYear = Integer.parseInt(year);
      sMonth= Integer.parseInt(month);
      sDay= Integer.parseInt(day);
      date = ((sYear*10000)+(sMonth*100)+(sDay));
      nameDoc=doctor;
      if(doctor.contains("myers"))
      {
      System.out.print(name+"\t");
      System.out.println(date);
      }
    getStandardTime(militaryTime);
    convertToLongDate(sYear,sMonth,sDay);

  }
  }

    public static String getStandardTime(String milTime)
    {
     int militaryHour = Integer.parseInt(milTime);
     int standardHour=0;
     String period = "";
     if((militaryHour>=12)&&(militaryHour<=24))
     {
       standardHour = militaryHour%12;
       period =standardHour +"pm";
     }else if((militaryHour<12)&&militaryHour>0){
       standardHour = militaryHour;
       period = standardHour+ "am";
     }
     return period;
    }
    public static long convertToLongDate(int m, int d, int y)
    {
      long date = ((y*10000)+(m*100)+(d));
      return date;
    }
}

there's more to it, but it pretty much looks like this

文件内容

SMITH_ALBERT 10 1 2015 0900 Myers
SMITH_BRYAN 10 1 2015 0930 Myers
SMITH_LAURA 10 1 2015 1000 Myers
SMITH_AL 10 1 2015 1030 Myers
SMITH_HOPE 10 1 2015 1100 Myers
SMITH_JAMES 10 1 2015 1315 Myers
SMITH_JADA 10 1 2015 1330 Myers
SMITH_CODY 10 1 2015 1400 Myers
SMITH_PAUL 10 1 2015 1410 Myers
SMITH_PETER 10 1 2015 1430 Myers
SMITH_JANE 10 1 2015 1500 Myers
SMITH_LARRY 10 1 2015 1530 Myers
SMITH_COREY 10 1 2015 1600 Myers
SMITH_JON 10 1 2015 1630 Myers
SMITH_STEVE 10 1 2015 1700 Myers
SMITH_MATT 10 1 2015 0000 Myers
SMITH_SAMUEL 10 1 2015 0000 Myers
SMITH_PAM 10 1 2015 0000 Myers
SMITH_MILTON 10 1 2015 0900 Myers
SMITH_ROCKY 10 1 2015 0930 Myers
SMITH_JACK 10 1 2015 1000 Myers
JONES_ALBERT 10 2 2015 0900 Armstrong
JONES_BRYAN 10 2 2015 0930 Armstrong
JONES_LAURA 10 2 2015 1000 Armstrong
JONES_AL 10 2 2015 1030 Armstrong
JONES_HOPE 10 2 2015 1100 Armstrong
JONES_JAMES 10 2 2015 1315 Armstrong
JONES_JADA 10 2 2015 1330 Armstrong
JONES_CODY 10 2 2015 1400 Armstrong
JONES_PAUL 10 2 2015 1410 Armstrong
JONES_PETER 10 2 2015 1430 Armstrong
JONES_JANE 10 2 2015 1500 Armstrong
JONES_LARRY 10 2 2015 1530 Armstrong
JONES_COREY 10 2 2015 1600 Armstrong
JONES_JON 10 2 2015 1630 Armstrong
JONES_STEVE 10 2 2015 1700 Armstrong
JONES_MATT 10 2 2015 0000 Armstrong
JONES_SAMUEL 10 2 2015 0000 Armstrong
JONES_PAM 10 2 2015 0000 Armstrong
JONES_MILTON 10 2 2015 0900 Armstrong
JONES_ROCKY 10 2 2015 0930 Armstrong
JONES_JACK 10 2 2015 1000 Armstrong
WILLIAMS_ALBERT 10 3 2015 0900 Myers
WILLIAMS_BRYAN 10 3 2015 0930 Myers
WILLIAMS_LAURA 10 3 2015 1000 Myers
WILLIAMS_AL 10 3 2015 1030 Myers
WILLIAMS_HOPE 10 3 2015 1100 Myers
WILLIAMS_JAMES 10 3 2015 1315 Myers
WILLIAMS_JADA 10 3 2015 1330 Myers
WILLIAMS_CODY 10 3 2015 1400 Myers
WILLIAMS_PAUL 10 3 2015 1410 Myers
WILLIAMS_PETER 10 3 2015 1430 Myers
WILLIAMS_JANE 10 3 2015 1500 Myers
WILLIAMS_LARRY 10 3 2015 1530 Myers
WILLIAMS_COREY 10 3 2015 1600 Myers
WILLIAMS_JON 10 3 2015 1630 Myers
WILLIAMS_STEVE 10 3 2015 1700 Myers
WILLIAMS_MATT 10 3 2015 0000 Myers
WILLIAMS_SAMUEL 10 3 2015 0000 Myers
WILLIAMS_PAM 10 3 2015 0000 Myers
WILLIAMS_MILTON 10 3 2015 0900 Myers
WILLIAMS_ROCKY 10 3 2015 0930 Myers
WILLIAMS_JACK 10 4 2015 1000 Armstrong
DUNN_ALBERT 10 4 2015 0900 Armstrong
DUNN_BRYAN 10 4 2015 0930 Armstrong
DUNN_LAURA 10 4 2015 1000 Armstrong
DUNN_AL 10 4 2015 1030 Armstrong
DUNN_HOPE 10 4 2015 1100 Armstrong
DUNN_JAMES 10 4 2015 1315 Armstrong
DUNN_JADA 10 4 2015 1330 Armstrong
DUNN_CODY 10 4 2015 1400 Armstrong
DUNN_PAUL 10 4 2015 1410 Armstrong
DUNN_PETER 10 4 2015 1430 Armstrong
DUNN_JANE 10 4 2015 1500 Armstrong
DUNN_LARRY 10 4 2015 1530 Armstrong
DUNN_COREY 10 4 2015 1600 Armstrong
DUNN_JON 10 4 2015 1630 Armstrong
DUNN_STEVE 10 4 2015 1700 Armstrong
DUNN_MATT 10 4 2015 0000 Armstrong
DUNN_SAMUEL 10 4 2015 0000 Armstrong
DUNN_PAM 10 4 2015 0000 Armstrong
DUNN_MILTON 10 4 2015 0900 Armstrong
DUNN_ROCKY 10 4 2015 0930 Armstrong
DUNN_JACK 10 4 2015 1000 Armstrong
MARS_ALBERT 10 5 2015 0900 Myers
MARS_BRYAN 10 5 2015 0930 Myers
MARS_LAURA 10 5 2015 1000 Myers
MARS_AL 10 5 2015 1030 Myers
MARS_HOPE 10 5 2015 1100 Myers
MARS_JAMES 10 5 2015 1315 Myers
MARS_JADA 10 5 2015 1330 Myers
MARS_CODY 10 5 2015 1400 Myers
MARS_PAUL 10 5 2015 1410 Myers
MARS_PETER 10 5 2015 1430 Myers
MARS_JANE 10 5 2015 1500 Myers
MARS_LARRY 10 5 2015 1530 Myers
MARS_COREY 10 5 2015 1600 Myers
MARS_JON 10 5 2015 1630 Myers
MARS_STEVE 10 5 2015 1700 Myers
MARS_MATT 10 5 2015 0000 Myers
MARS_SAMUEL 10 5 2015 0000 Myers
MARS_PAM 10 5 2015 0000 Myers
MARS_MILTON 10 5 2015 0900 Myers
MARS_ROCKY 10 5 2015 0930 Myers
MARS_JACK 10 5 2015 1000 Myers
VENUS_ALBERT 10 6 2015 0900 Armstrong
VENUS_BRYAN 10 6 2015 0930 Armstrong
VENUS_LAURA 10 6 2015 1000 Armstrong
VENUS_AL 10 6 2015 1030 Armstrong
VENUS_HOPE 10 6 2015 1100 Armstrong
VENUS_JAMES 10 6 2015 1315 Armstrong
VENUS_JADA 10 6 2015 1330 Armstrong
VENUS_CODY 10 6 2015 1400 Armstrong
VENUS_PAUL 10 6 2015 1410 Armstrong
VENUS_PETER 10 6 2015 1430 Armstrong
VENUS_JANE 10 6 2015 1500 Armstrong
VENUS_LARRY 10 6 2015 1530 Armstrong
VENUS_COREY 10 6 2015 1600 Armstrong
VENUS_JON 10 6 2015 1630 Armstrong
VENUS_STEVE 10 6 2015 1700 Armstrong
VENUS_MATT 10 6 2015 0000 Armstrong
VENUS_SAMUEL 10 6 2015 0000 Armstrong
VENUS_PAM 10 6 2015 0000 Armstrong
VENUS_MILTON 10 6 2015 0900 Armstrong
VENUS_ROCKY 10 6 2015 0930 Armstrong
VENUS_JACK 10 6 2015 1000 Armstrong
SATURN_ALBERT 10 7 2015 0900 Myers
SATURN_BRYAN 10 7 2015 0930 Myers
SATURN_LAURA 10 7 2015 1000 Myers
SATURN_AL 10 7 2015 1030 Myers
SATURN_HOPE 10 7 2015 1100 Myers
SATURN_JAMES 10 7 2015 1315 Myers
SATURN_JADA 10 7 2015   1330 Myers
SATURN_CODY 10 7 2015   1400 Myers
SATURN_PAUL 10 7 2015   1410 Myers
SATURN_PETER 10 7 2015  1430 Myers
SATURN_JANE 10 7 2015   1500 Myers
SATURN_LARRY 10 7 2015  1530 Myers
SATURN_COREY 10 7 2015 1600 Myers
SATURN_JON 10 7 2015 1630 Myers
SATURN_STEVE 10 7 2015 1700 Myers
SATURN_MATT 10 7 2015 0000 Myers
SATURN_SAMUEL 10 7 2015 0000 Myers
SATURN_PAM 10 7 2015 0000 Myers
SATURN_MILTON 10 7 2015 0900 Myers
SATURN_ROCKY 10 7 2015 0930 Myers
SATURN_JACK 10 8 2015 1000 Armstrong
NEPTUNE_ALBERT 10 8 2015 0900 Armstrong
NEPTUNE_BRYAN 10 8 2015 0930 Armstrong
NEPTUNE_LAURA 10 8 2015 1000 Armstrong
NEPTUNE_AL 10 8 2015 1030 Armstrong
NEPTUNE_HOPE 10 8 2015 1100 Armstrong
NEPTUNE_JAMES 10 8 2015 1315 Armstrong
NEPTUNE_JADA 10 8 2015 1330 Armstrong
NEPTUNE_CODY 10 8 2015 1400 Armstrong
NEPTUNE_PAUL 10 8 2015 1410 Armstrong
NEPTUNE_PETER 10 8 2015 1430 Armstrong
NEPTUNE_JANE 10 8 2015 1500 Armstrong
NEPTUNE_LARRY 10 8 2015 1530 Armstrong
NEPTUNE_COREY 10 8 2015 1600 Armstrong
NEPTUNE_JON 10 8 2015 1630 Armstrong
NEPTUNE_STEVE 10 8 2015 1700 Armstrong
NEPTUNE_MATT 10 8 2015 0000 Armstrong
NEPTUNE_SAMUEL 10 8 2015 0000 Armstrong
NEPTUNE_PAM 10 8 2015 0000 Armstrong
NEPTUNE_MILTON 10 8 2015 0900 Armstrong
NEPTUNE_ROCKY 10 8 2015 0930 Armstrong
NEPTUNE_JACK 10 8 2015 1000 Armstrong

0 个答案:

没有答案