Answered step by step
Verified Expert Solution
Question
1 Approved Answer
we just pick it randomly 0% 0 of 1 topics complete Exercise 05 Assignment Due February 21 at 11:59 PM Exercise 05 Starts Feb 17,
we just pick it randomly
0% 0 of 1 topics complete Exercise 05 Assignment Due February 21 at 11:59 PM Exercise 05 Starts Feb 17, 2020 2:00 PM Ends Feb 24, 2020 11:59 PM Using Figure 6-10 on page 293 as a guide, use NetBeans IDE and write a CLI application that does following: Ask for a number between 1-5 from user . You pick one number from 1-5 and use it as the correct number: If the user specified number is not correct, output the incorrect number and ask the user to enter it again. If the user specified number is correct, output the correct number, thank the user for participating, and terminate the program. . Finally, take a screenshot of your CLI outputs and then submit it along with your zipped NetBeans project folder of this exercise to e-Learning. import java.util.Scanner: public class EnterSmallValue public static void main(String[] args) int user Entry: final int LIMIT -3: Scanner input = new Scanner(System.in): System.out.print("Please enter an integer no higher than " + LIMIT + " "): userEntry input.nextInt : while(userEntry > LIMIT) System.out.println("The number you entered was too high"): System.out.print("Please enter an integer no higher than " + LIMIT + " "); userEntry - input.nextInto: System.out.println("You correctly entered userEntry): Figure 6-10 The EnterSmallValue application Note ==>> . Make sure to che guide and follow Creating while Loops art java.util.Scanner: c class EnterSmallValue Wic static void main(String[] args) int userEntry: final int LIMIT - 3; ner input - new Scanner(System.in. ut.print("Please enter an integer ne higher than . System.out.print("Please LIMIT + " "); userEntry - input.nextInt : while(userEntry > LIMIT) The while statement controls the loop stem.out.println("The number you entered was too high"): System.out.print("Please enter an integer no higher than LIMIT + " "); user Entry input.nextInt : The loop body is between the curly races System.out.println("You correctly entered userEntry): Figure 6-10 The EnterSmallValue application Figure 6-11 shows a typical execution of the program in Figure 6-10. While the user continues to enter incorrect data, the loop repeats. It ends only when a value of 3 or less is entered Please enter an integer no higher than 3 > 7 The number you entered was too high Please enter an integer no higher than 3 > 5 The number you entered was too high Please enter an integer no higher than 3 > 4 The number you entered was too high Please enter an integer no higher than 3 > 3 Vou correctly entered 3 Figure 6-11 Typical execution of the EnterSmallValue program rigure 6-10 illustrates an excellent method for validating input. Before the loop is entered, first input value is retrieved. This first input might be a value that prevents any executions of the loop. This first input statement prior to the loop is called a priming read Priming input. Within the loop, the last statement retrieves subsequent input values for the same variable that will be checked at the entrance to the loop. Vice programmers often make the mistake of checking for invalid data using a decision ad of a loop. That is, they ask whether the data is invalid using an if statement; if the invalid, they reprompt the user. However, they forget that a user might enter incorrect tiple times. Usually a loop is the best structure to use when validating input data data multiple times 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