Skip to content

Instantly share code, notes, and snippets.

@luisenriquecorona
Last active January 18, 2020 07:20
Show Gist options
  • Save luisenriquecorona/4be7f3e3054b47d642a2dcbf7ab4dea6 to your computer and use it in GitHub Desktop.
Save luisenriquecorona/4be7f3e3054b47d642a2dcbf7ab4dea6 to your computer and use it in GitHub Desktop.
Do the variables need a more meaningful context? The function name provides only part of the context; the algorithm provides the rest.
private void printGuessStatistics(char candidate, int count) {
String number;
String verb;
String pluralModifier;
if (count == 0) {
number = "no";
verb = "are";
pluralModifier = "s";
} else if (count == 1) {
number = "1";
verb = "is";
pluralModifier = "";
} else {
number = Integer.toString(count);
verb = "are";
pluralModifier = "s";
}
String guessMessage = String.format(
"There %s %s %s%s", verb, number, candidate, pluralModifier
);
print(guessMessage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment