I'm currently working on a programming assignment for school. It's a simple text-based RPG. When I test the program locally (by hand), it works correctly. However, when I submit it to the grading server, it creates some sort of infinite loop.
I emailed my professor, who responded by explaining how the server tested the program. It uses the following format: java IPA1 (XML file name) < (Input file) > (output file). IPA1 is the name of the main java file. It seems that the < (Input file) is causing the endless loop for some reason... but I cannot pinpoint why.
My program gets its input with the following code:
boolean gameOver = false;
while (!gameOver) {
Command cmd = inputParser.getCommand();
gameOver = processCommand(cmd);
}
The getCommand(cmd) is as follows:
public Command getCommand() {
String input = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
input = reader.readLine();
} catch(java.io.IOException exc) {
System.out.println ("Error");
}
return new Command(input);
}
My question is: Why would this work when I type each command in sequentially by hand... but fail when an input file is used?