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(fileName));
// 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+", Batting average: "+((double)hCount/(double)(hCount+oCount)));
wCount=0;hCount=0;sCount=0;oCount=0;
}
}
}
the output shows the name and their stats correctly, but when counting outs or w/e it also counts os in the name so the numbers aren't correct is there any way to fix this?