This is where I am now:
import java.util.Scanner;
import java.io.*;
public class BaseballStats
{
//-------------------------------------------------
// Reads baseball stats from a file and counts
// total hits, outs, walks, and sacrifice flies
// for each player.
//-------------------------------------------------
public static void main (String[] args) throws IOException
{
Scanner fileScan, lineScan;
String fileName;
int oCount=0, hCount=0, sCount=0, wCount=0;
Scanner scan = new Scanner(System.in);
System.out.print ("Enter the name of the input file: ");
fileName = scan.nextLine();
fileScan = new Scanner(new File("stats.dat"));
// Read and process each line of the file
while (fileScan.hasNext())
{
fileName=fileScan.nextLine();
//System.out.println (" " +fileName);
lineScan = new Scanner (fileName);
lineScan.useDelimiter(",");
for (int i=0; i< fileName.length(); i++)
{
if (fileName.charAt(i) == 's')
{
sCount++;
}
else if (fileName.charAt(i) == 'o')
{
oCount++;
}
else if(fileName.charAt(i) == 'h')
{
hCount++;
}
else if (fileName.charAt(i) == 'w')
{
wCount++;
}
}
System.out.println(lineScan.next()+" Walks: "+wCount+" Hits: "+hCount+" Sacrifice: "+sCount+" Outs: "+oCount);
}
}
}
It takes a running count of all stats but I only want stats per player...how do I do that?
Here is the text file I'm reading from:
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,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