Reading statistics from a file
<p>One of the homework assignments my instructor gave me was a baseball statistics program. It reads from a file called stats.dat, which contains the name of a baseball player's name and a list of what happened when they were at the bat. It reads and prints their name and the amount of outs(o), hits(h), walks(w), and sacrifice flies(s) that they have. This is what the file contains:</p>

<pre><code>Willy Wonk,o,o,h,o,o,o,o,h,w,o,o,o,o,s,h,o,h
Shari Jones,h,o,o,s,s,h,o,o,o,h,o,o,o
Barry Bands,h,h,w,o,o,o,w,h,o,o,h,h,o,o,w,w,w,h,o,o
Sally Slugger,o,h,h,o,o,h,h,w
Missy Lots,o,o,s,o,o,w,o,o,o
Joe Jones,o,h,o,o,o,o,h,h,o,o,o,o,w,o,o,o,h,o,h,h
Larry Loop,w,s,o,o,o,h,o,o,h,s,o,o,o,h,h
Sarah Swift,o,o,o,o,h,h,w,o,o,o
Bill Bird,h,o,h,o,h,w,o,o,o,h,s,s,h,o,o,o,o,o,o
Don Daring,o,o,h,h,o,o,h,o,h,o,o,o,o,o,o,h
Jill Jet,o,s,s,h,o,o,h,h,o,o,o,h,o,h,w,o,o,h,h,o
</code></pre>

<p>So far I have the basic idea down, even though I don't quite understand what each line is doing(I modified some code of a program in the book my class is reading that prints a URL that's in a text file and then prints out each part of the url that's separated by a /). I have it so that the program prints out the player's name, but I'm stumped on how to print out the amount of hits, outs, walks, and sacrifice flies they get. So far it's reading 1 character out of the line, then it goes down to the next player and prints out 2, then 3, etc. Here's the code I have for it so far:</p>

<pre><code>import java.util.Scanner;
import java.io.*;

public class BaseballStats
{
 public static void main(String [] args) throws IOException
 {
  int hit = 0, walk = 0, sac = 0, out = 0, length = 0, wholeLength = 0;
  Scanner fileScan, lineScan, statScan;
  String fileName, playerName, line, stats, playerStats;
  Scanner scan = new Scanner(System.in);

  System.out.println("Enter the name of the file: ");
  fileName = scan.nextLine();
  fileScan = new Scanner(new File(fileName));

  while (fileScan.hasNext())
  {
   System.out.println();
   line = ("Player: " + fileScan.nextLine());
   wholeLength = line.length();

   lineScan = new Scanner(line);
   lineScan.useDelimiter(",");

   stats = lineScan.next();
   statScan = new Scanner(stats);
   statScan.useDelimiter(",");


   while (statScan.hasNext())
   {
    System.out.println(statScan.next());
    length = stats.length() - 1;


    for (int i = 0; i &lt; length; i++)
    {
      if (stats.charAt(i) == 'h')
        hit++;
      else if (stats.charAt(i) == 'o')
        out++;
      else if (stats.charAt(i) == 'w')
        walk++;
      else if (stats.charAt(i) == 's')
        sac++;
    }
   }
    System.out.println("Hits: " + hit + "\nOuts: " + out + "\nWalks: " + walk +              "\nSacrifice flies: " + sac);
  }
 }
}
</code></pre>

<p>(I'm having a hard time getting the last part of the last statement in my code to appear correctly in the editor, sorry if it looks a bit weird) I have been wondering what's wrong and I can't figure it out so far. Is there anything to get me on the right track?</p>
