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

  1. Create a directory "FSCORE" (or whatever you would like to call it) on your hard drive.
  2. Down load the program ftbprog.java from the internet.
  3. Down load the program jsplit.java from the internet.
  4. Set the path so that you can compile and execute a Java program.
  5. Execute this command line at the MS-DOS command prompt:
    javac jsplit.java
    This will compile jsplit.java to create jsplit.class.
  6. 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.
  7. 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.
  8. 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: 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 Play

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.

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


Notes about the program

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