Question
SoftballTeam.java Requirements and Design: The SoftballTeam class provides methods for reading in the data file and generating reports. Design: In addition to the specifications in
SoftballTeam.java Requirements and Design: The SoftballTeam class provides methods for reading in the data file and generating reports. Design: In addition to the specifications in Project 10, the existing readPlayerFile method must be modified to catch following: InvalidCategoryException and NumberFormatException. o readPlayerFile has no return value and accepts the data file name as a String. Remember to include the throws IOException clause in the method declaration. This method creates a Scanner object to read in the file and then reads it in line by line. The first line contains the team name and each of the remaining lines contains the data for a player. After reading in the team name, the player lines should be processed as follows. A player line is read in, a second scanner is created on the line, and the individual values for the player are read in. After the values on the line have been read in, an appropriate SoftballPlayer object created. If there is room on the roster, the player is added to the roster array and the player count is incremented. Any player lines/records read from the file after the limit of MAX_PLAYERS players has been reached should be added to the excluded array with appropriate prefix message (Maximum player count of ___ exceeded for: where the blank is MAX_PLAYERS) and its count should be incremented. If excluded array is full, the line/record should just be skipped. The data file is a comma separated values file; i.e., if a line contains multiple values, the values are delimited by commas. So when you set up the scanner for the player lines, you need to set the delimiter to use a , by calling the useDelimiter(",") method on the Scanner object. Each player line in the file begins with a category for the softball player (O, I, P, and R are valid categories for softball players indicating Outfielder, Infielder, Pitcher, and ReliefPitcher respectively. The second field in the record is the players number, followed by the data for the name, position, specialization factor, and batting average. The last items correspond to the data needed for the particular category (or subclass) of SoftballPlayer. For each incorrect line scanned (i.e., a line of data contains an invalid category or invalid numeric data), your method will need to handle the invalid items properly. If the line of data begins with an invalid category, your program should throw an InvalidCategoryException (see description above). If a line of data has a valid category, but includes invalid numeric data (e.g., the value for battingAvg contains an alphabetic character), a NumberFormatException (see notes on last page) will be thrown automatically by the Java Runtime Environment (JRE). The code that checks for player category should be in a try statement and the code that adds a record with an invalid player category to the excluded records array should now be placed in the catch clause the follows the try statement. That is, your readPlayerFile method should catch and handle InvalidCategoryException and NumberFormatException as follows. In each catch clause, a String object should be created consisting of e + " in: " + line where e is the exception and line is the line with the invalid data. The String object should be added to the excludedRecords array.
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