I have two methods here that does the same thing. get the user input and validate them. if they are enter a letter program will prompt him again to enter a number after that if its a number it will compare it to the bound given by the program or the user. it is working fine. but can anybody help me refactor this code? since it would be really helpful if I could disect the validations into smaller pieces of code or method
public void addToQuestionToQbank(){
this.askForCategory();
System.out.println("Add Questions[1]Multiple Choice[2] Identification: ");
int choice;
boolean notValid = true;
do{
while(!input.hasNextInt()){
System.out.println("Numbers Only!");
System.out.print("Try again: ");
input.nextLine();
}
notValid = false;
choice = input.nextInt();
}while(notValid);
while(choice > 2){
System.out.println("Out of bounds");
choice = input.nextInt();
input.nextLine();
}
}
public Difficulty askForDifficulty(){
System.out.println("Difficulty For This Question:\n1)Easy\n2)Medium\n3)Hard\nChoice: ");
int choice = 0;
boolean notValid = true;
do{
while(!input.hasNextInt()){
System.out.println("Numbers Only!");
System.out.print("Try again: ");
input.nextLine();
}
notValid = false;
choice = input.nextInt();
}while(notValid);
while(choice > diff.length){
System.out.println("Out of bounds");
choice = input.nextInt();
input.nextLine();
}
System.out.println(diff[choice -1]);
return diff[choice -1];
}