Question
Question: *JAVA* Please help with the promptUser method. It needs to keep looping until a correct int is entered. Welcome to Mine Sweeper! What width
Question: *JAVA* Please help with the promptUser method. It needs to keep looping until a correct int is entered.
Welcome to Mine Sweeper! What width of map would you...
*JAVA* Here's what output should look like.
Welcome to Mine Sweeper! What width of map would you like (3 - 20): three Expected a number from 3 to 20. 2 Expected a number from 3 to 20. 5 What height of map would you like (3 - 20): 22 Expected a number from 3 to 20. ten or eleven Expected a number from 3 to 20. 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . row: 12 Expected a number from 1 to 10. 5 column: red Expected a number from 1 to 5. 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Would you like to play again (y/n)? yes!! What width of map would you like (3 - 20): 4 What height of map would you like (3 - 20): 4 . . . . . . . . . . . . . . . . row: 5 Expected a number from 1 to 4. 4 column: 4 . . . . . . . . . . . . . . . Would you like to play again (y/n)? nope Thank you for playing Mine Sweeper!
import java.util.Random;
import java.util.Scanner;
public class MineSweeper {
/**
* This is the main method for Mine Sweeper game!
* This method contains the within game and play again loops and calls
* the various supporting methods.
*
* @param args (unused)
*/
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
System.out.println("Welcome to Mine Sweeper!");
}
/**
* This method prompts the user for a number, verifies that it is between min
* and max, inclusive, before returning the number.
*
* If the number entered is not between min and max then the user is shown
* an error message and given another opportunity to enter a number.
* If min is 1 and max is 5 the error message is:
* Expected a number from 1 to 5.
*
* If the user enters characters, words or anything other than a valid int then
* the user is shown the same message. The entering of characters other
* than a valid int is detected using Scanner's methods (hasNextInt) and
* does not use exception handling.
*
* Do not use constants in this method, only use the min and max passed
* in parameters for all comparisons and messages.
* Do not create an instance of Scanner in this method, pass the reference
* to the Scanner in main, to this method.
* The entire prompt should be passed in and printed out.
*
* @param in The reference to the instance of Scanner created in main.
* @param prompt The text prompt that is shown once to the user.
* @param min The minimum value that the user must enter.
* @param max The maximum value that the user must enter.
* @return The integer that the user entered that is between min and max,
* inclusive.
*/
public static int promptUser(Scanner in, String prompt, int min, int max) {
return -99; //FIXME
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started