Note: no late submissions will be accepted for this assignment.
This assignment involves using inheritance to calculate statistics on a baseball or softball team. The BallPlayer class is provided for you, which encapsulates basic information about a baseball/softball player (uniform number, first and last names, and position). In addition, the TeamStats class is able to read in a roster of players from a file and display that roster.
Create a GUI that allows the user to specify a file containing baseball/softball player info (roster.txt is provided as an example). At the click of a button, the contents of that file should be read into a
TeamStats object and the results of a call to the
roster method displayed in a text area. For example:
Typically, different performance statistics are kept for players depending on whether they are batters (i.e., position players) or pitchers. For batters, batting average, number of home runs, runs scored, and runs batted in are among the statistics commonly reported. However, pitchers rarely have these offensive statistics reported. Instead, statistics such as earned run average, walks and hits allowed, wins, and saves are reported.
The Batter class extends
BallPlayer to include batting statistics (number of hits and number of at bats).
BallPlayerto include pitching statistics (number of earned runs allowed and number of innings pitched). Note that the number of innings pitched may include fractions of innings, so must be represented as a real value. Your class should have methods for accessing the number of earned runs and innings pitched, and also for calculating the earned run average. Earned run average (ERA) is the average number of runs allowed per nine innings pitched. For example, if a pitcher allowed 3 earned runs in 12 innings, then his/her ERA would be 9*(3/12) = 2.25. As was the case with the
toStringmethod should return the basic player information along with the pitcher's ERA.
TeamStatsclass so that it reads in a file of statistics, such as stats.txt. Each line contains the uniform number, name, and position of a player. If that player is a pitcher (i.e., position is "SP" or "RP"), then what follows are the number of earned runs and innings pitched for that player. If that player is a batter (i.e., anything but "SP" and "RP"), then what follows are the number of hits and at bats. The
TeamStatsconstructor will need to read in the initial values on each line to determine the player's position, then construct the appropriate type of object (either
Pitcher) and add it to the ArrayList. You should also add methods to
TeamStatsthat calculate the team batting average and team earned run average. In order to do this, you will need to be able to determine the specific type of each object in the ArrayList using the
instanceofoperator. For example,