Using .dat files in UIL competitions
Why?
When starting the programming portion of a UIL competition, the challenges will more than likely require you to process your input through a .dat
file. You may not know how to read a file from the disk, or properly parse its contents. This guide shows you how the UIL graders are expecting you to.
Important note
This guide is assuming you’re using jGrasp and all your Java source files, compiled .class
files, and .dat
files are in the same directory for simplicity.
What the heck is a .dat
file?
The extension .dat
is used to denote miscellaneous data. The .dat
files used in UIL competitions are plain-text files with sample input data that you can use to test your code. Usually they’re the exact same text that’s on your printed out instructions. These are no different from a .txt
file made in notepad.
How do I parse a dat file?
In Java, or any programming language, there are a limitless amount of ways to read data from a file and do what you want with it. What is expected at UIL, though, is to focus on the challenge of deriving an algorithm to solve a bigger problem, instead of being stumped by how you should be reading a file.
The recommended way is to use the two classes: Scanner and File.
These are the same classes you’ve probably used to receive input you’ve typed into your Java programs before. (Here’s a quick refresher)
Example
input.dat
ReadingDatFiles.java
Console output
Real UIL solution using a .dat
file
Thanks to: Mike Scott at the University of Texas
burpees.dat
Burpees.java
Console output
Sources: uiltexas.org, utexas.edu