Created
February 26, 2020 01:08
-
-
Save luisenriquecorona/1e3e285eaa551a74c5cbad5deb7c077f to your computer and use it in GitHub Desktop.
The function is a bit too long and the variables are used throughout. To split the func- tion into smaller pieces we need to create a GuessStatisticsMessage class and make the three variables fields of this class. This provides a clear context for the three variables. They are definitively part of the GuessStatisticsMessage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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