The local Kids' League coach keeps some of the baseball team statistics in a text file...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The local Kids' League coach keeps some of the baseball team statistics in a text file organized as follows: each line of the file contains the name of the player followed by a list of symbols indicating what happened on each at-bat for the player. The letter h indicates a hit, o an out, w a walk, and s a sacrifice fly. Each item on the line is separated by a comma. There are no blank spaces except in the player name. So, for example the file could look as follows: Sam Slugger, h, h, o, s,w, w, h, w, o, o, o,h, s Jill Jenks, o, o, s,h, h, 0,0 Will Jones, o, o,w,h,0,0,0,0,0,0,0 The file BaseballStats.java contains the skeleton of a program that reads and processes a file in this format. Study the program and note that three Scanner objects are declared. One scanner (scan) is used to read in a file name from standard input. The file name is then used to create a scanner (fileScan) to operate on that file. A third scanner (lineScan) will be used to parse each line in the file. • Also note that the main method throws an FileNotFoundException. This is needed in case there is a problem opening the file. Complete the program as follows: 1. 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 files stats.dat and stats2.dat. import java.util.Scanner; * 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. * @author blink * */ 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 FileNot FoundException Scanner fileScan; Scanner lineScan; String fileName; Scanner scan = new Scanner (System.in); //TODO Read and process each line of the file System.out.print ("Enter the name of the input file: "); fileName = scan.nextLine(); fileScan = new Scanner (new File (fileName)); The local Kids' League coach keeps some of the baseball team statistics in a text file organized as follows: each line of the file contains the name of the player followed by a list of symbols The local Kids' League coach keeps some of the baseball team statistics in a text file organized as follows: each line of the file contains the name of the player followed by a list of symbols indicating what happened on each at-bat for the player. The letter h indicates a hit, o an out, w a walk, and s a sacrifice fly. Each item on the line is separated by a comma. There are no blank spaces except in the player name. So, for example the file could look as follows: Sam Slugger, h, h, o, s,w, w, h, w, o, o, o,h, s Jill Jenks, o, o, s,h, h, 0,0 Will Jones, o, o,w,h,0,0,0,0,0,0,0 The file BaseballStats.java contains the skeleton of a program that reads and processes a file in this format. Study the program and note that three Scanner objects are declared. One scanner (scan) is used to read in a file name from standard input. The file name is then used to create a scanner (fileScan) to operate on that file. A third scanner (lineScan) will be used to parse each line in the file. • Also note that the main method throws an FileNotFoundException. This is needed in case there is a problem opening the file. Complete the program as follows: 1. 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 files stats.dat and stats2.dat. indicating what happened on each at-bat for the player. The letter h indicates a hit, o an out, w a walk, and s a sacrifice fly. Each item on the line is separated by a comma. There are no blank spaces except in the player name. So, for example the file could look as follows: Sam Slugger, h, h, o, s,w, w, h, w, o, o, o,h, s Jill Jenks, o, o, s,h, h, 0,0 Will Jones, o, o,w,h,0,0,0,0,0,0,0 The file BaseballStats.java contains the skeleton of a program that reads and processes a file in this format. Study the program and note that three Scanner objects are declared. One scanner (scan) is used to read in a file name from standard input. The file name is then used to create a scanner (fileScan) to operate on that file. A third scanner (lineScan) will be used to parse each line in the file. • Also note that the main method throws an FileNotFoundException. This is needed in case there is a problem opening the file. Complete the program as follows: 1. 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 files stats.dat and stats2.dat. import java.util.Scanner; * 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. * @author blink * */ 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 FileNot FoundException Scanner fileScan; Scanner lineScan; String fileName; Scanner scan = new Scanner (System.in); //TODO Read and process each line of the file System.out.print ("Enter the name of the input file: "); fileName = scan.nextLine(); fileScan = new Scanner (new File (fileName)); import java.util.Scanner; * 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. * @author blink * */ 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 FileNot FoundException Scanner fileScan; Scanner lineScan; String fileName; Scanner scan = new Scanner (System.in); //TODO Read and process each line of the file System.out.print ("Enter the name of the input file: "); fileName = scan.nextLine(); fileScan = new Scanner (new File (fileName));
Expert Answer:
Answer rating: 100% (QA)
import javaioFile import javaioFileNotFoundException import javautilScanner public class BaseballSta... View the full answer
Related Book For
Data Modeling and Database Design
ISBN: 978-1285085258
2nd edition
Authors: Narayan S. Umanath, Richard W. Scammel
Posted Date:
Students also viewed these programming questions
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Once an LLC has engaged in a dissolution procedure, the business does not stop immediately. True/False
-
What is the key distinction between grouped and ungrouped data?
-
Use matrices A, B, C, and D to find the indicated matrices. If the operations cannot be performed, explain why. 2C + D A || 6-3 4 -5 B 1) -1 4 -7 2 -6 11 3 12 -9 -6 D= 79 -6 -4 0 8 16000
-
At 3:00 a.m. on November 22, 2010, 16-year-old Sydney McLemore was driving a Mazda3 with her friend, Natalie Hurst, in the front passenger seat. The vehicle was traveling south on Ross Bridge Highway...
-
On January 1, 2011, Secada Co. leased a building to Ryker Inc. The relevant information related to the lease is as follows. 1. The lease arrangement is for 10 years. 2. The leased building cost...
-
Direct Materials Conversion Percent Percent Units Complete Beginning work in process inventory 2,800 100% Complete 25% Units started this period 6,800 Completed and transferred out 7,800 Ending work...
-
You are stealing irreplaceable dodo eggs, each of mass M, from a research laboratory from the laboratory roof to a getaway truck filled with pillows. To clear the security egg launcher at 0 degrees...
-
Submissions attempt.d21?ou-375815&q=3482798a-572 A Question 27 0/15 points Dr. Gregory Whittpenn is a respected local plastic surgeon in Nacogdoches who performs reconstructive nose surgeries....
-
Let k, L > 0 and suppose u(x, t) satisfies the Dirichlet problem u(x, 0) = 0, u(0, t) = u(L, t) = 0, ut - kurr - sin u, where 0 < x < L and t 0. Show that there exists a constant C> 0 such that for...
-
If Gary's Shoes pays Al Bundy a salary of $25,000 per year and decided to pay all of it shoe managers overtime (even though this is not required by law for salaried workers) for all hours over 40...
-
how has recent inflation impacted financial planning. In your initial post, address the following: Describe the monetary impact of inflation. Describe what a CFP professional will need to communicate...
-
You short-sell 200 shares of Tommy co. now selling for $37 per share. If you wish to limit your loss to $1,450, you should place a stop-buy order at what price? You purchased 250 shares of common...
-
Describe briefly the quark model of hadrons, including the properties of quarks.
-
Write the given system without the use of matrices. D) - ()- d (x sin t + 8 (2+ 1)
-
Modify the pervious query to that instead of displaying as one of the totals the total number pounds of milk produced in each region, the total number of pounds of milk produced in each year across...
-
What four deletion rules are applicable to deletion constraints? Which rule(s) refer to an action on the parent and which rule(s) refer to an action on the child?
-
Display the number of pounds of milk produced in each region each year along with the total number of pounds produced in each region, the total number of pounds of milk produced during each year and...
-
The SDLC is just one model for systems development. Find at least one more and describe the differences.
-
Draw DFDs for each of these scenarios: (a) A customer goes into a bookshop and asks for this book. The member of staff looks for the book in the online stock catalogue and reports that the book is...
-
Draw an entity model to model this university scenario: A university department employs lecturers and clerical staff. It offers a three-year degree. A student has to take 12 modules during the...
Study smarter with the SolutionInn App