I'm in an intro cse class using Java and I have a new homework where I create a Mad Lib game using File Processing.
I am wondering what the best approach is to replace a String placeholder with an adjective like "cool"
Here is a small portion of my code
PrintStream fileOutput = new PrintStream(new File(fileName));
Scanner fileScan = new Scanner(new File(fileName));
while (fileScan.hasNextLine()) {
String line = fileScan.nextLine();
Scanner word = new Scanner(line);
while (word.hasNext()) {
String token = word.next();
if (token.startsWith("<") && token.endsWith(">")) {
token = token.replace("<", "");
token = token.replace(">", "");
}
fileOutput.print(token + " ");
}
}
I currently got the '<' and '>' characters taken care of but I am unsure what the best approach is to replace the characters in between the two brackets. For example if I identify a token is a placeholder and is adjective I would prompt the user to "Type an adjective" and a noun "Type a noun" using the correct a/an structure. On past assignments I would get the right external correctness but my style is "bad" or "incorrect"