Skip to content
Snippets Groups Projects
Commit b46f356e authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Extracted getUserInput as a helper method for multiple methods

parent 0d63a2d9
No related branches found
No related tags found
No related merge requests found
...@@ -10,15 +10,22 @@ public class Statistics { ...@@ -10,15 +10,22 @@ public class Statistics {
MEAN, MEDIAN, MAXIMUM, MINIMUM, MEAN, MEDIAN, MAXIMUM, MINIMUM,
} }
private static String getUserInput(String prompt, Scanner scanner) {
System.out.print(prompt);
String userInput = scanner.nextLine();
return userInput;
}
private static double getValue(String ordinal, Scanner scanner) { private static double getValue(String ordinal, Scanner scanner) {
System.out.print("Enter the " + ordinal + " value: "); String userInput = getUserInput("Enter the " + ordinal + " value: ", scanner);
double value = Double.parseDouble(scanner.nextLine()); double value;
value = Double.parseDouble(userInput);
return value; return value;
} }
private static StatisticsType getStaticsticsType(Scanner scanner) { private static StatisticsType getStaticsticsType(Scanner scanner) {
System.out.print("Please enter the statistic to calculate: "); String userInput = getUserInput("Please enter the statistic to calculate: ", scanner);
String userInput = scanner.nextLine().toUpperCase(); userInput = userInput.toUpperCase();
StatisticsType statisticsType = StatisticsType.valueOf(userInput); StatisticsType statisticsType = StatisticsType.valueOf(userInput);
return statisticsType; return statisticsType;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment