Question: COMP 1900- Fall 2018 Lab 5: More Loops! (15 pts) Number of People: Individual Dus: By the end of your lab session today. You MUST

 COMP 1900- Fall 2018 Lab 5: More Loops! (15 pts) Number
of People: Individual Dus: By the end of your lab session today.
You MUST submit this be Grader. Please refer to the COMP Coding

COMP 1900- Fall 2018 Lab 5: More Loops! (15 pts) Number of People: Individual Dus: By the end of your lab session today. You MUST submit this be Grader. Please refer to the COMP Coding Style: Use camelCase for variable names, use consistent indentation 1900 sylabus for your lab TA. Questions about grading? Contact him/her first in your code, and include a reasonable poor coding style. amount of comments throughout your code. The TAs may deduct points for Within the 1900 folder on your desktop, create a new folder named La bs 1. (6 pts) When reading input from the user, we should never assume the user will enter valid input. that For example, a program that asks the user to enter a n umerical grade should verify that the input is a number between 0 and 100. If the input is invalid, we generally want the program to show an errOr message and ask the user to enter the input again. This process is called input validation A simple way of doing input validation is using an if statement 1 Scanner input new Scanner (System.in) : 3 Systen.out.printin("Enter a grade (0-100) ") 4 double grade input.nextDouble) 5 if (grade 100) /7 Lf grade is invalid systen.out.prinein ("Grade nust be betveen 0 and 100, try again!) grade-input. nextDouble) 10 Use the variable grade in the rest of the progran Do you see the problem with the code above? If the user enters an invalid grade in line 4, s/he sees the error message in line 6 and gets the opportunity to re-enter the grade in line 7. However, if the user enters another invalid grade in line 7, the code simply proceeds past the if statement to the rest of the program, without giving the user the chance to correct the invalid entry Within your Lab5 folder, create a new file named In that it does the following: putValidation.java. Modify the code above so re-entering invalid grades up to 4 times. Use a loop for this, rather than The user can keep multiple nested if statements Once the user . has entered a valid grade, the program shows the final (valid) grade that was tries to enter 5 invalid grades, the program exits and displays a sufficiently entered and the number of invalid grades that were entered If the user error message examples of what the program might look like while running (the The back of this page has some underlined parts indicate user input). what the

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!