Use double to store bets

The original basic allowed fractional bets.
This commit is contained in:
Dave Burke
2022-02-11 13:02:22 -06:00
parent df86d49bb7
commit db1e32a314
3 changed files with 36 additions and 11 deletions

View File

@@ -132,4 +132,29 @@ public class UserIo {
}
}
}
/**
* Prompts the user for a double. As in Vintage Basic, "the optional
* prompt string is followed by a question mark and a space." and if the
* input is non-numeric, "an error will be generated and the user will be
* re-prompted.""
*
* @param prompt The prompt to display to the user.
* @return the number given by the user.
*/
public double promptDouble(String prompt) {
print(prompt + "? ");
while(true) {
String input = readLine();
try {
return Double.parseDouble(input);
} catch(NumberFormatException e) {
// Input was not numeric.
println("!NUMBER EXPECTED - RETRY INPUT LINE");
print("? ");
continue;
}
}
}
}