Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // get the difficulty level as a character
- // Input: no input, but this method listens to users' keyboard input
- // Output: char 'e', 'i', or 'h'
- public static char difficulty() {
- char level;
- while(true) {
- System.out.println("Enter your difficulty level:");
- Scanner keyboard = new Scanner(System.in);
- String input = keyboard.nextLine().toLowerCase();
- try {
- if (validation(input) == true) {
- level = getLevel(input);
- return level;
- } else {
- System.out.println("Your input is invalid. "
- ."Please re-enter your difficulty level:");
- }
- } catch (NumberFormatException nFE){
- System.out.println("Your input is invalid. "
- ."Please re-enter your difficulty level:");
- }
- }
- }
- // validate the input
- // Input: Users' input as a string
- // Output: true or false
- private static boolean validation(String str) {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement