Java Grade Analyzer: What I Learned Writing Input Validation From Scratch
This was a school assignment. Read a text file with sections of grades. Compute the average, highest, lowest, and letter distribution for each section and overall. Print the results to the console and write them to a file. Standard first-year CS project. The assignment required it in Java, and I was using vim for the first time with no run button.
The interesting part was not the grade analysis. The interesting part was the 346-line input validation library I wrote alongside the 271 lines of actual program logic.
Validation Without Exceptions
The HelpCode class validates every input character by character before attempting conversion. It checks for valid digits, counts decimal points and sign characters, and rejects non-numeric input at the string level instead of catching a NumberFormatException. The checkNum method tracks three counters: positive signs, negative signs, and decimal separators. If any counter exceeds its allowed limit or a non-numeric character appears, the method returns false before the program ever tries to parse.
This is overkill for a grade analyzer that reads integers from a well-structured file. The file format is predictable. Section headers declare the count, and every following line contains an integer. A simple exception handler would have covered every realistic failure case in fewer lines. But I was learning, and I wanted to understand how validation works under the abstraction.
The Grade Analysis
The main loop reads a filename, opens it, and processes sections until the file ends. Each section starts with a count, followed by that many grades. Running totals track the sum, minimum, maximum, and grade counts for both section-level and aggregate statistics. The output prints formatted tables to the console and writes identical tables to an output file named out prepended to the original filename.
The quit command is cheeseburger. I thought it was funny at the time.
What I Would Change
The validation library is separate from the main program but tightly coupled to its specific input format. It could be reusable. It is not. The file path handling uses forward slashes directly, which breaks on Windows. There is no try-with-resources. The grades use hardcoded thresholds for A through F with no way to adjust them.
It processes grades. It writes reports. The validation system is larger than the program it validates. That imbalance is the most honest reflection of where I was as a programmer at the time.