title: Counting the number of errors in a text file
body: <p>I've written a program that reads in a text file to show football scores, now the text file is arranged so that it has errors included and I'm trying to write a program to count these errors. The text file is arranged like so:</p>
  
  <pre><code>Hull City : Sunderland : 2 : 3
  Chelsea : Manchester City :1
  Fulham : Leeds United : 1 : 2
  Wigan : Tottenham : 1 : x
  : :2:0
  </code></pre>
  
  <p>So the above has missing team names, missing scores and some scores replaced with an X. I can't for the life of me figure out how to introduce a counter to count the number of errors, any idea on a starting point/solution would be much appreciated, thanks!</p>
  
  <p>Here is my full code:
  Main:</p>
  
  <pre><code>public class main {
  
  public static void main(String[] args) {
  
      String userInput;
  
      readFile readScores = new readFile();
  
      do 
      {
          userInput = readScores.getUserInput();
          if(userInput.equalsIgnoreCase("S"))
              readScores.printScores();
              readScores.totalGoals();
              readScores.errorCount();
  
      } while (!userInput.equalsIgnoreCase("E"));
          System.out.println("****************Exiting application****************");
          System.exit(0);
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Readfile Class:</p>
  
  <pre><code>public class readFile {
  
  
  String [] stringArr;
  
  Scanner scan = new Scanner(System.in);
  
  public String getUserInput()
  {
      String userInput;
  
      System.out.println("Select your option:\nS - Show Scores \nE - Exit");
  
      userInput = scan.nextLine();
  
      return (userInput);
  
  }
  
  public void printScores()
  {
  
      String sep = ":";
      File inputfile = new File ("P:/SD/Assignment1/results2.txt");
  
          String line = "";
  
  
  
          try {
              Scanner filescan = new Scanner(inputfile);
              while(filescan.hasNext())
              {
                  line = filescan.nextLine();
  
  
                  stringArr = line.split(sep);
                  if(stringArr.length ==  4)
                  {                       
  
                      System.out.println(stringArr[0]+"\t [" +stringArr[2]+"]\t|" + stringArr[1]+"\t["+ stringArr[3]+" ]\n");
  
  
                  }
  
                  else
                  {
                      throw new IllegalArgumentException("String " + line + " does not contain " + sep);
                  }
  
  
  
               }
              filescan.close();
  
  
          }
              catch (FileNotFoundException e)
              {
                  System.out.println("problem " +e.getMessage());
              }
  
          }
      public void totalGoals()
      {
  
          int[] num = new int[stringArr.length]; 
          int count = 0;
          for (int i = 0; i&lt;stringArr.length; i++)
          {
              System.out.println(stringArr[i]);
              num[i] = Integer.parseInt(stringArr[i]);
              count = count + num[i];
              System.out.println(count);
          }
      }
  
      public void errorCount()
      {
          String line;
          int errorCount=0;
          String[] strArr;
          try
          {
  
              BufferedReader br = new BufferedReader(new FileReader("P:/SD/Assignment1/results2.txt"));
              while(line = br.readLine() != null)
              {
                  strArr = line.split(":");
                  if(strArr.length==4){
                      if(strArr[1].trim().isEmpty()) errorCount++;
                      if(strArr[2].trim().isEmpty()) errorCount++;
                      if(strArr[3].trim().indexOf("x")&gt;=0) errorCount++;
                      if(strArr[4].trim().indexOf("x")&gt;=0) errorCount++;
                  }
              }
          }
          catch(Exception e){
              //error handling
          }
          System.out.println("Error count: "+errorCount);
      }
      }
  </code></pre>
  
  <p>UPDATE::</p>
  
  <pre><code>public void errorCount()
          {
  
          String line;
          int errorCount=0;
          String[] strArr;
          String[] parts = line.split(":"); &lt;--- ERROR IS HERE
          if (parts.length != 4) {
              errorCount++;
  
          }
          for (String part : parts) {
              if (part.trim().isEmpty()) {
                  errorCount++;
                  break; 
              }
          }
          if (!(isNumeric(parts[2].trim()) &amp;&amp; isNumeric(parts[3].trim()))) { //counts one error, otherwise, check each one of them and if both are not numeric, count this as two errors
              errorCount++;
              // continue with the following line
          }
      }
  </code></pre>