For this program, we need to read in a file which has baseball stats. Our program reads in the dat file then parses each line in the file. The file looks like this:
Joe h,o,h,s,h,o,h,h,h,o,o,o
Bill s,o,o,h,h,o,s,s,o
So far I'm ok with this. Here is the part that I'm struggling with. We have to modify the inner loop that parses a line in the file to count (seperately) the number of h, o, and s in each line.
Any help would be appreciated.
Here is my java program so far.
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;
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();
lineScan = new Scanner (fileName);
lineScan.useDelimiter(",");
while (lineScan.hasNext())
lineScan.next();
System.out.println();
}
}
}