Question: (Java) My code is good so far, but am still missing some components. How do I use the sentinel loop pattern to ask the user

(Java) My code is good so far, but am still missing some components. How do I use the sentinel loop pattern to ask the user if the would like to play a game at the beginning, and if they wished to play again at the end. Lastly, if the user enters an invalid range number, for example: if the prompt is pick a number between 0-10, and they pick 199, how do i tell them to pick a valid number.
(Java) My code is good so far, but am still missing some
components. How do I use the sentinel loop pattern to ask the
user if the would like to play a game at the beginning,

1 package com.company; 2 3 import java.util.Scanner; class scratch { //Class Name 6 public static void main(String[] args) { Scanner input = new Scanner(System.in); 7 8 9 int max, min, guess, secret, maxAttempts = 0; 10 11 System.out.println("What would be the low range: "); min = input.nextInt(); 12 13 14 System.out.println("high range: "); max = input.nextInt(); 15 16 17 secret = (int) (Math.random() * (max - min + 1) + min); //Secret Number System.out.println("Please pick a number between " + min + "." + max); 18 19 20 21 while (maxattempts secret) { System.out.println("Too high"); System.out.println("Please pick a number between + guess); } else { System.out.println("Congrats"); } maxAttempts++; 31 32 e 33 34 e 35 36 11 + secret); 38 System.out.println("The number was 39 } 40 41 42 } 43 YOUT yuess 15 222 Too low Please pick a number between 222-500 Your guess is: 111 Too low Please pick a number between 111-500 Your guess is: I 44 1. Structure Too low Please pick a number between 44-500 The number was 321 Bookmarks Process finished with exit code Bulld Problems Terminal Run Warrion Control 1E TODO

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!