I'm taking a beginning java class and I'm trying to create a helper method to get a input from a user and combine all four methods into a package I can use in my programs after. I keep running into trouble with the last method, getMenuStringFromUser, the error it gives me says java cannot find symbol method getIntegerFromUser(java.lang.String,int,int) here's what i have so far
package bulletproof;
import java.util.*;
//BULLETPROOF METHOD FOR INTEGERS
// better general method with low and high limits
class getIntegerFromUser {
public static int getIntegerFromUser(String prompt, int low, int high) {
Scanner keyboard = new Scanner(System.in);
while (true) { // keep asking until we get an integer within limits low and high
System.out.print(prompt);
try {
String input = keyboard.nextLine(); // read next line
int theInteger = Integer.parseInt(input);
if (low <= theInteger && theInteger <= high)
return theInteger;
}
catch (NumberFormatException e1) {}
catch (NoSuchElementException e2) {}
System.out.print("\nPlease enter a number within limits [" + low + "-" + high + "].\n");
keyboard.close();
keyboard = new Scanner(System.in);
}
}
}
//BULLETPROOF METHOD FOR DOUBLE
class getDoubleFromUser {
public static double getDoubleFromUser(String prompt, double low, double high) {
Scanner keyboard = new Scanner(System.in);
while (true) { // keep asking until we get an integer within limits low and high
System.out.print(prompt);
try {
String input = keyboard.nextLine(); // read next line
double theDouble = Double.parseDouble(input);
if (low <= theDouble && theDouble <= high)
return theDouble;
}
catch (NumberFormatException e1) {}
catch (NoSuchElementException e2) {}
System.out.print("\nPlease enter a number within limits [" + low + "-" + high + "].\n");
keyboard.close();
keyboard = new Scanner(System.in);
}
}
}
//BULLETPROOF METHOD FOR STRINGS
class getStringFromUser {
public static String getStringFromUser(String prompt) {
Scanner keyboard = new Scanner(System.in);
while (true) { // keep asking until we get valid input
try {
System.out.print(prompt);
String input = keyboard.nextLine().trim(); // trim the whitespace (leading and trailing white space)
if (input.length() > 0) // then make sure there's at least one non-white space character
return input;
}
catch (NoSuchElementException nsee) {}
System.out.println("\nPlease enter text (ex. yes)\n");
keyboard.close();
keyboard = new Scanner(System.in);
}
}
}
class getMenuStringFromUser {
public static String getMenuStringFromUser(String title, String...items) {
Scanner keyboard = new Scanner(System.in);
//First build the menu title and items, putting a number before each item
String menu = title + "\n\n";
int count=0;
while (count < items.length) {
menu += "" + (count+1) + "." +items[count] + "\n";
count++;
}
menu += "\nPlease enter your selection [1-" + items.length + "]: ";
// Now call getIntegerFromUser to display the menu to get the user's numeric response
int num = getIntegerFromUser(menu, 1, items.length);
//Finally, return the String the user selected
return items [num-1];
}
}