Football Statistics Program
from Java Programming the Easy Way, by Douglas Downing
published by Barron's Educational Series
Click here to see the combined source code file for the program
Click here to see the source code for the program to split
the combined source code file into the individual source code files
Click here for more information about
the Java source code files in the program.
Click here to return to Java Programming the Easy Way home page
This program provides a way to keep track of the statistics for
a football game on a computer, and it also displays a diagram showing the
movement of the ball up and down the field.
Even if you will not be using this program during a football
game, you can look at the source code to see some examples of
a complicated application written in Java.
Setting up the program
There are several Java source files that make up this program.
However, they have all been grouped in one file:
ftblprog.java
to make it easier for you to download the entire source code
in one move. You can execute this program:
jsplit.java
to split up the files into the individual source code files;
it will also create a batch file COMP.BAT that will cause
all of these files to be automatically compiled.
After you compile the program, use the command
java fscore
to begin program execution. (fscore is short
for "football scorekeeper.")
( Click here for more information about
the Java source code files in the program.
Summary of steps to load and run the program
- Create a directory "FSCORE" (or whatever you would like to call it) on your
hard drive.
- Down load the program
ftbprog.java from the internet.
- Down load the program
jsplit.java from the internet.
- Set the path so that you can compile and execute a Java program.
- Execute this command line at the MS-DOS command prompt:
javac jsplit.java
This will compile jsplit.java to create jsplit.class.
- Execute the jsplit program with this command line:
java jsplit ftbprog.java
Note that ftbprog.java is given to the program as the command line
argument. This program will create several files of type java, and
it will also create comp.bat.
- Type the command line
comp
to execute the batch file COMP.BAT. This will call the Java compiler to
compile all of the source codes.
- Now you're ready to execute the FSCORE program with the command line
java fscore
If you'd like, you can create the bat file FSCORE.BAT containing the
single line
java fscore
Then you can create a shortcut to that bat file so it can be executed
directly from the Windows desktop (without entering the MS-DOS prompt first).
Starting a game
To run the program, you need to create one file for each team; these
files contain the player names, numbers, and positions.
From the File menu, choose CreateTeamFile.
A dialog box will appear for you to fill in player names,
positions, and numbers. Use these abbreviations for players:
- QB:quarterback
- RB:running back
- WR: wide receiver
- TE:tight end
- K: kicker
- P: punter
At the start of the game, you only need to enter the names of
those players that will show up on the statistics for ballcarriers
(you can add more players during the course of the game if necessary; for
example, if a defensive player scores a touchdown).
Also, each team needs to have a one-letter abbreviation
to identify yard lines. For example, if you call the teams
H and V for home and visitor, then H20 would refer to the home
team's 20 yard line and V40 would refer to the visiting team's
40 yard line.
If the two teams start with different letters, then it is easiest
to use the first letter of each team name as the abbreviation;
if they start with the same letter you'll have to think of some other
letters to use for abbreviations. (Throughout this description of
the program, the letters H and V will always be used to designate
the two teams, but remember that when you use the program you will
be using the correct letters for the teams that are actually playing.)
You can also create the team files with any text editor; the
first line of the file is the team name, the second line
is the one letter abbreviation, and the remaining lines identify
players, in this form:
Smith,10,QB
where Smith is the player's name, 10 is the number, and QB is the position.
When entering the names, it is best if the starters are listed
before reserves. The program will assume that the first QB listed
is the starting quarterback, the first kicker listed is the starting
kicker, etc.
After the team files are created, then load them with the
Load option under the File menu.
The game can begin only after the teams are loaded.
Changing Colors. The Edit
menu also allows you to change the colors of the teams so that they
will more closely match their actual colors (although
a team with color green will be harder to see against the green
background of the field diagram).
Game Action
To start the game, select the receiving team from the
Kickoff menu. A dialog box will appear for you
to enter information about the return.
Here's an example:
80 H2 H20
Use spaces to separate the three items.
In this case 80 is the number of the player who returns the
kick. The return starts at the home team 2 yard line and ends
at the home team 20 yard line.
A confirmation dialog box will appear; click OK if this
is correct (or click cancel if you need to reenter this information).
As with all of these confirmation boxes, you also have the opportunity
to add a note that will appear on the play by play description.
You might use these notes to indicate who made the tackle, or
the direction of the play, or the time on the clock.
Game Action screen
The Game Action screen is the screen that will normally show when
the game is going on. It has these elements:
- Game diagram at the top of the screen. Each play will be represented
by a line on the diagram, so you can see how far the ball moved during that play.
Each team has its own color.
The beginning of a first down play is marked with a hollow circle;
the beginning of other plays is marked with a solid circle.
A loss is generally represented as a diagonal line.
An abbreviation appears on the diagram at the end of each
drive to indicate the result of that drive.
In the diagram the team with blue jerseys moves to the left; their drives
result in punt, field goal, interception, punt return touchdown,
safety, and end of half.
The team with white jerseys (shown on the diagram in red because that shows
up better than white) moves to the left; their drives result in
punt, punt, fumble, punt, touchdown, missed field goal.
A detailed description of each play will be generated on the
play by play screen.
You can adjust the appearance of the game diagram with these options
under the View menu:
- Full Screen Diagram: As the game progresses, the game diagram will
become too large to completely fit in the space at the top of the Game
Action screen. If you switch to Full Screen Diagram, then the game
diagram will fill the whole screen. Switch back to Game Action to
continue the game.
- Reverse Direction: The teams switch sides at the end of the
first and third quarters (and maybe at halftime). However, the game
diagram will show each team moving in the same direction the entire
game, to make it easier to see the progress that each team is making.
You can reverse the directions on the game diagram so they match
your view of the actual game.
For example, if the home team is moving to the right as seen from
your vantage point in the first quarter, you should set the game
diagram so that the home team moves to the right, and then reverse
the direction at the start of the second quarter.
- Adjust Diagram: You can slide the diagram up or down in its box,
or increase or decrease the separation between the lines.
- Scoreboard (lower left): The scoreboard gives basic
current information about the game (the score, down, yards to
gain for a first down, which team has the ball, the current yard line,
and the quarter. The scoreboard will also tell how successful the
offensive team has been on this down. For example:
3rd: 2-5 avg gain: 4.3
means that the current offensive team has played 5 third
downs; they have made a first down on 2 of those; and they
have gained an average of 4.3 yards on third down plays.
The scoreboard will also give the number of plays and yards
in the current drive, and the number of total rushing and passing yards
for the offensive team.
- Rushing table (lower middle): This table lists some of
the players on the offensive team that have carried the ball;
their number of carries; and their total rushing yards.
- Passing table (lower right): This table lists the quarterback
of the offensive team, along with passes completed, attempted, had
intercepted, and total yards passing.
- Receiving table (lower right): This table lists some of the
players on the offensive team that have caught the ball and yards
gained receiving.
Game Play
- Rushing play:
If the ball carrier's name appears on the rushing table,
then click on that name.
A yard line display will appear on the screen; click on the
number corresponding to the gain (or loss) on the play.
(Note: the white numbers that appear below the green numbers
give the yard line where the play ends. Particularly if the
play is a long gain, it is quicker to identify the yard line where
the play ended than it is to
calculate the yards gained. However, you need to click on the
green numbers.
If the numbers you need do not appear on the screen, then click
on the arrows (either to the left or the right) to adjust the
yard line display. For example, if there is a 30 yard gain, you
will need to click on the right arrow until the green number 30
appears in the list.
If the ball carrier's name does not appear on the rushing table,
then choose the "Rushing" item from the "Play" menu.
A dialog box will appear; enter the number of the ball carrier
and the yardline where the play ends up. For example:
32 V28
means that player 32 carried the ball to the visiting team's 28
yard line.
If you enter the number of a player who is not already in the computer,
then another dialog box will appear asking you to give the name
and number for this player. -
In all cases, a confirmation dialog box will appear
to allow you to verify that the play has been entered correctly
and allow you to add a note.
- Passing play:
If the passer appears on the passing table, and the
receiver appears on the receiver table, then enter a
passing play like this:
- Click on the passing player's name in the passing table.
- Click on the receiving player's name in the receiver table.
(Also, you may click on a player on the rushing list if one of
those players catches the pass.)
- Click on the yard line indicator to indicate the gain. (This
works the same as it does for a running play.)
If you don't see both the passer's name (on the passing table) and
the receiver's name (on the receiving or rushing table) then enter a
passing play as follows:
- Choose "Passing" from the "Play" menu.
- A dialog box will appear; enter the passing play information
like this:
12-80 V15
if 12 is the number of the passer, 80 is the number of the
receiver, and V15 is the final yard line.
For an incomplete pass, click on the passer's name in the passing
list, then click on "0" in the yard table.
Suppose that a new quarterback enters the game and throws
the incomplete pass, or suppose a player other than the
quarterback throws the pass.
In that case, the passer's name is not the name that appears on
the passing list.
Then you need to use the "New Passer" option in the "Play" menu
to set the new passer. (You need to do this before
you can enter an incomplete pass.)
If the pass is intercepted, then choose "Interception" from the
"Play" menu. A dialog box will appear; enter information giving
the number of the player making the interception, the yard line
at the start, and the yard line at the end. For example:
40 V35
means that player 40 carries the ball to the visitor
35 yard line.
It is automatically assumed that the player appearing on the
passing list is the one who threw the interception; if another
player was the passer, then you need to use the "New Passer" option
in the "Play" menu to set the passer before selecting the Incomplete
menu item.
- Punt: Choose the "Punt" item from the "Play" menu.
A dialog box will appear; enter the player number of the punter,
then the yard line where the punt lands. For example:
10 V25
means that player 10 punted the ball and it landed on the
visitor's 25 yard line.
A new dialog box will appear asking for information about the
return. For example:
40 V35
means that player 40 carries the ball to the visitor
35 yard line.
If a home team player returns the punt for a touchdown,
then enter "V0" for the yard line.
If there is no return, then click the "Cancel" button
in the punt return dialog box. For example, if
player 18 for the home team punts the ball to the
end zone, then enter
18 V0
in the punt dialog box, and click "Cancel"
in the punt return dialog box.
- Scoring a touchdown: If a touchdown is scored on a rushing
or passing play, simply enter the number for the gain that takes
the ball to the end zone (for example, enter a 25 yard gain if the
ball is on the defender's 25 yard line, and enter a 75 yard gain
if the ball is on the offensive team's 25 yard line).
- Conversion:
- After a touchdown is scored, a conversion dialog box will appear.
This box will display text showing the name of the team's kicker,
followed by the word kick. If this player successfully completes
the convesion, then simply click "OK".
- If another player kicks
the conversion, then edit the text box to fill in the new name.
Be sure to leave the word "kick" if the kick is successful.
- If the kick fails, then put the words "kick failed" in the
dialog box.
- If a two point conversion succeeds, then enter text like this
in the dialog box: "runningback_name run" or "receiver_name pass from
quarterback_name".
- If a two point conversion fails, then enter the text
"run failed" or "pass failed".
- Conversion summary: the word "failed" will tell the computer
that the conversion failed. If that word is not present, then the
computer will assume that the conversion succeeded. If the word
"kick" is present, then it will be a one point conversion; otherwise
it will be a two-point conversion. (There is
one other extremely unlikely possibility.)
- Scoring a touchdown on a punt, kickoff, interception, or fumble
return: When the dialog box for the return appears, enter
"V0" or "H0" to indicate that the return reached the visitor's goal
line (or the home team's goal line).
- Field Goals: Select "Field Goal" from
the "Play" menu; the program will guess that the default kicker
made the kick and that the distance is 17 yards plus the distance
from the line of scrimmage to the goal line. You can change these
in the scoring description if necessary.
- Missed Field Goals:Select "Missed Field Goal"
from the "Play" menu. Most commonly, a missed field goal is followed
by the other team taking over the ball at the line of scrimmage (or
the 20 yard line, if the line of scrimmage is inside the 20 yard
line.) If this is the case, then click OK on the confirm dialog
box and the next play will be set automatically.
However, in some cases a missed field goal can be returned;
in that case, click "Cancel" on the first dialog box you see;
then click "Ok" on the next dialog box to confirm that a missed
field goal really did occur (otherwise click cancel). A
new dialog box will ask for information about the field goal
return: the player returning the ball and the yard line at the
end of the return.
View menu
The View
menu shows the different screen views that are available.
For these screens, if some of the text has fallen off the
bottom edge of the screen, then you can click on a line
to scroll the text up. Then, click on the top line to
scroll the text down.
- Scoring:
This view shows a list of scoring plays, plus the
score by quarters.
- Statistics: This view shows individual statistics for rushing,
passing, receiving, punting, and returns of punts, kickoffs, and
interceptions.
- Team statistics: This view shows total yards gained for each
team, results for each down (giving number of plays for each down,
number of those converted to first downs, and average gain for that
down); and turnovers.
- Rosters: This view shows a list of the player names, numbers,
and positions.
- Play-by-play: This view lists all of the plays in the game.
For a scrimmage play, the first number gives the line number (all lines
of the play by play list are numbered consecutively); this is followed
by a quarter indicator (such as Q1 for the first quarter); then an
indicator of who has the ball, the down and distance, and the yard
line at the start of the play, followed by a description of the
result of the play.
If you added a descriptive note to that play (for example,
saying who made the tackle), this note will appear on the
play-by-play view.
- Drive summary: This view shows a list of each drive, showing
where it started, how much was gained, and the result. Also included
is a table summarizing the results of the drives.
Recording time of possession
At the end of each drive, a dialog box will appear asking for the time
on the clock at the end of that drive (for example, enter 7:32 if there
are 7 minutes, 32 seconds left in the current quarter). This information
will be used to calculate time of possession. However, if you don't wish
to keep track of this information, the choose the Edit
menu option to turn this feature off. A dialog box will appear to
confirm your choice. If you turn this off, then you can't turn it
back on again (since information would be lost if you have not recorded
the time at the end of each drive.)
You can also record the scoreboard time in the note section for any
play if you wish.
Saving the game results
At the end of the game, choose "Write to File" from the "File" menu
to create a text file with the statistics and play-by-play of the
game. To save the game diagram, press the "Print Screen" key when
the game diagram is on the screen. This will create a bitmap image
of the screen and save it on the clipboard. Then enter any program
that can read in a bitmap image (such as the Paint program); paste
the image into this program, and then save it to a file.
Special events
- Onside kicks: In this case, the receiving team is the
same as the kicking team. Otherwise, it is a normal kickoff
return.
- Drive that ends on the last play of a half: If a team
scores or commits a turnover on the last play of a half,
then a "dummy" drive will be created for the other team.
This drive will be recorded as having 0 plays and ending
with the end of half. (Reason: There will always be two drives
that end with "end of half" in a game.)
- Defensive two point conversion:
If the defender returns
the ball all the way down the field on a conversion, then enter
the word "(defense)" in the conversion description and the
two points will be awarded to the defensive team.
Here is a list of the java source files for this program.
These are general files that you can use in other programs:
screenclass.java
screenelement.java
screenparam.java
These are the dialog boxes used by the program (some of these
can also be used in other programs):
readteam.java
readteamname.java
colorselector.java
ftbinbox.java
confirmbox.java
standardcolorselector.java
mbox.java
The remaining files are specific to this football program.
Each drive ends with a particular type of drive end event;
each of these events is represented by a class that extends
the class driveendclass.
These are arranged in order from good to bad:
driveendclass.java
touchdown.java
fieldgoal.java
puntclass.java
missedfieldgoal.java
fourdown.java
eoh.java
interception.java
fumble.java
safety.java
A drive often begins with a return event; different kinds of
return events all extend returnclass:
returnclass.java
puntreturnclass.java
kickreturnclass.java
fumbreturnclass.java
intreturnclass.java
mfgreturnclass.java
Different types of scrimmage plays extend scrimmageplayclass (plus
one special class: returntdclass).
scrimmageplayclass.java
rushplayclass.java
passplayclass.java
penplayclass.java
fieldgoalscrim.java
sackplayclass.java
returntdclass.java
The following classes all represent items of special importance
in a football game:
yardlineclass.java
playerclass.java
ftbteam.java
diagramparameters.java
ftbfield.java
footballtime.java
driveclass.java
playclass.java
statclass.java
Finally, this is the file with the main method:
fscore.java
The source code of the program contains some System.out.println
statements enclosed in comments; these were included during the
process of developing the program to make it possible to see what
was happening at a particular point.
This file is generated from the outline file
fscore.out
using the code generator program included in the
disc that came with the book. (If you want to add
new features to this program, it would be easier to work
with the outline code rather than the java source code.)
The combined source code file was created using the program
javacomb.java
You may find this useful with your own programs if you wish
to combine several source code files into one that can later
be split with
jsplit.java