From b46f356e9940bf378b3ace03d7b41d0eac087581 Mon Sep 17 00:00:00 2001
From: Christopher Bohn <bohn@unl.edu>
Date: Mon, 11 Oct 2021 08:11:51 -0500
Subject: [PATCH] Extracted getUserInput as a helper method for multiple
 methods

---
 .../unl/cse/soft160/statistics/Statistics.java    | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/java/edu/unl/cse/soft160/statistics/Statistics.java b/src/main/java/edu/unl/cse/soft160/statistics/Statistics.java
index b2d8a37..5230ad6 100644
--- a/src/main/java/edu/unl/cse/soft160/statistics/Statistics.java
+++ b/src/main/java/edu/unl/cse/soft160/statistics/Statistics.java
@@ -9,16 +9,23 @@ public class Statistics {
 	public enum StatisticsType {
 		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) {
-		System.out.print("Enter the " + ordinal + " value: ");
-		double value = Double.parseDouble(scanner.nextLine());
+		String userInput = getUserInput("Enter the " + ordinal + " value: ", scanner);
+		double value;
+		value = Double.parseDouble(userInput);
 		return value;
 	}
 
 	private static StatisticsType getStaticsticsType(Scanner scanner) {
-		System.out.print("Please enter the statistic to calculate: ");
-		String userInput = scanner.nextLine().toUpperCase();
+		String userInput = getUserInput("Please enter the statistic to calculate: ", scanner);
+		userInput = userInput.toUpperCase();
 		StatisticsType statisticsType = StatisticsType.valueOf(userInput);
 		return statisticsType;
 	}
-- 
GitLab