Question
Read Baseball Stats from a Text File Purpose Practice reading data from a text file. You can write the source code in one of these
Read Baseball Stats from a Text File Purpose Practice reading data from a text file. You can write the source code in one of these languages: Java, C, C++, Python, C#, or VB. (java) We can use the same Scanner Class to read a text file. Need to read one line of text at a time, and process it. Detect of End Of File so know how many records to read in. Format of the Text File 1. Line 1: will have the players name 2. Line 2 - Line ??: Have the players stats for a single game. a. Sample stats for a line in the text file. 5, 3, 0, 0, 1, 2 b. The data is: AtBats, Hits, Double, Triples, Homeruns, Walks. Calculations Needed 3. Batting Average = (Hits / AtBats) * 1000. Truncate any decimal value. 4. Slugging Pct = ( (#Homeruns * 4) + (#Triples * 3) + (#Doubles * 2) + #singles ) / (AtBats) 5. You'll have to calculate the number of singles. Requirements 6. Create a Java class named CSC141_Baseballstats. 7. Use the File class and the Scanner class to open the text file for reading. 8. Once open, read the first line which is the players name, using .nextLine(). 9. Read the other lines (loop) in as a String, using .nextLine().
Please complete the following exercise in python. Please use this data in your text file. Don't forget to indent your code in the answer and to attach the screenshots of the code and the output.
Mike Trout 5,3,0,0,1,2 3,4,0,1,1,2 5,8,3,1,9,6 2,7,4,0,6,4 3,7,5,0,3,2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started