Handle 'an' vs 'a' grammar

This commit is contained in:
Dave Burke
2022-03-05 09:53:41 -06:00
parent d6e0edb75f
commit ca0906cbfc
2 changed files with 18 additions and 14 deletions

View File

@@ -61,6 +61,19 @@ public final class Card {
return result.toString();
}
/**
* Returns the value of {@link #toString()} preceded by either "AN " or "A " depending on which is gramatically correct.
*
* @return "AN [x]" when [x] is "an" ace or "an" 8, and "A [X]" otherwise.
*/
public String toProseString() {
if(value == 1 || value == 8) {
return "AN " + toString();
} else {
return "A " + toString();
}
}
@Override
public boolean equals(Object obj) {
// Overriding 'equals' and 'hashCode' (below) make your class work correctly