Question: First add a while loop that reads each line in the file and prints out each part (name, then each at bat, without the commas)

First add a while loop that reads each line in the file and prints out each part (name, then each at bat, without the commas) in a way similar to the URLDissector program in Listing 5.10 of the text. In particular inside the loop you need to a. read the next line from the file b. create a comma delimited scanner (lineScan) to parse the line c. read and print the name of the player, and finally, d. have a loop that prints each at bat code. 2. Compile and run the program to be sure it works. 3. Now modify the inner loop that parses a line in the file so that instead of printing each part it counts (separately) the number of hits, outs, walks, and sacrifices. Each of these summary statistics, as well as the batting average, should be printed for each player. Recall that the batting average is the number of hits divided by the total number of hits and outs. 4. Test the program on the file stats.dat and stats2.dat

. // **************************************************************** // BaseballStats.java // //

Reads baseball data in from a comma delimited file. Each line

// of the file contains a name followed by a list of symbols

// indicating the result of each at bat: h for hit, o for out,

// w for walk, s for sacrifice. Statistics are computed and // printed for each player.

// **************************************************************** import java.util.Scanner; import java.io.*;

// ****************************************************************

// BaseballStats.java // // Reads baseball data in from a comma delimited file. Each line

// of the file contains a name followed by a list of symbols // indicating the result of each at bat: h for hit, o for out,

// w for walk, s for sacrifice. Statistics are computed and // printed for each player.

// **************************************************************** 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 76

{ 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(fileName));

// Read and process each line of the file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!