Do you need an outer and/or inner loop for a nested do loop?

Do you need an outer and/or inner loop for a nested do loop?

import java.util.Random;

import java.util.Scanner;

public class GuessingGame {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

scan.useDelimiter(“\r\n”);

boolean guessAgain;

boolean keepPlaying = true;

String userOption;

String difficulty;

System.out.println(“Welcome to the quessing game, where you will try to guess a random number.”);

System.out.println(“You are able to select from the following levels of difficulty for the game:”);

System.out.println(“Easy = Numbers 0 to 5\r\nMedium = Numbers 0 to 10 ” +

“\r\nHard = Numbers 0 to 20\r\nImpossible = Numbers 0 to 50” );

System.out.println();

do{

System.out.println(“Please select the level of difficulty:”);

System.out.println(“E for Easy\tM for Medium\tH for Hard\tI for Impossible”);

difficulty = scan.next().toUpperCase();

// START A NESTED DO LOOP

guessAgain = true;

// CREATE A SWITCH STATEMENT THAT EVALUATES THE difficulty VARIABLE

// CREATE CASE STATEMENTS FOR THE LETTERS “E”, “M”, “H”, “I”, AND A DEFAULT

// CASE

// IF THE CASE IS EQUAL TO “E” CALL THE checkGuess METHOD WITH THIS CALL:

// guessAgain = checkGuess(6);

// IF THE CASE IS EQUAL TO “M” CALL THE checkGuess METHOD WITH THIS CALL:

// guessAgain = checkGuess(11);

// IF THE CASE IS EQUAL TO “H” CALL THE checkGuess METHOD WITH THIS CALL:

// guessAgain = checkGuess(21);

// IF THE CASE IS EQUAL TO “I” CALL THE checkGuess METHOD WITH THIS CALL:

// guessAgain = checkGuess(51);

// OTHERWISE, DEFAULT TO PROMPT THE USER THAT THE OPTION IS INVALID,

// AND HE/SHE SHOULD ENTER ‘Q’ TO QUIT

// OR ANY OTHER KEY TO TRY AGAIN

userOption = scan.next();

System.out.println();

// CREATE AN IF ELSE STATEMENT THAT COMPARES THE userOption VARIABLE TO

// THE LETTERS “Q” AND “D”

// IF IT IS “Q” SET THE keepPlaying VARIABLE TO false, OTHERWISE, IF keepPlaying

// EQUALS “D” SET THE

// guessAgain VARIABLE TO false.

// CLOSE THE NESTED DO LOOP WITH A WHILE STATEMENT THAT CHECKS IF guessAgain

// AND keepPlaying ARE TRUE

}while(keepPlaying);

System.out.println(“Thank you for playing.”);

}

private static boolean checkGuess(int maxNumber) {

System.out.println(“Please guess a number between 0 and ” + maxNumber);

Random randomNumber = new Random();

Scanner scan = new Scanner(System.in);

int guess = scan.nextInt();

int number = randomNumber.nextInt(maxNumber);

// CHECK IF number EQUALS guess, IF IT DOES THEN PERFORM THE STATEMENTS BELOW

// System.out.println(“Congratulations!! You guessed correctly!!”);

// System.out.println(“Please enter ‘Q’ to quit, or any other key to try again .”);

// return false;

// IF number DOES NOT EQUAL guess, THEN PERFORM THE STATEMENTS BELOW

// System.out.print(“I’m sorry, the number was ” + number + ” Please guess again.”);

// System.out.println();

// System.out.println(“Please enter ‘D’ to choose a different difficulty level, ” +

// “‘Q’ to quit, or any other key to try again .”);

// return true;

}

}

Complete Answer:

Get Instant Help in Homework Asap
Get Instant Help in Homework Asap
Calculate your paper price
Pages (550 words)
Approximate price: -
Open chat
1
Hello 👋
Thank you for choosing our assignment help service!
How can I help you?