Answered step by step
Verified Expert Solution
Question
1 Approved Answer
WRITE PROGRAM IN JAVA CODING ! Counter-Controlled While Loop Lab Write a program that does the following: Prompts the user for the number of grades
WRITE PROGRAM IN JAVA CODING !
Counter-Controlled While Loop Lab
Write a program that does the following:
- Prompts the user for the number of grades they wish to enter.
- IF the number of grades is zero THEN
- Display an error message
- ELSE
- Using a counter-controlled WHILE loop, prompt the User to enter a grade and compute a running total of the grades entered.
- IF the number of grades is not equal to zero THEN
- Calculate the average of the grades entered.
- You are testing BEFORE computing the average to prevent a division by zero. Make sure the average is not computed if the number of grades is zero.
- Print out a message stating the average of the grades entered.
- END IF
Include the following:
- Use a counter-controlled WHILE loop that uses the number of grades entered by the User as the maximum number of loops executed.
- Initialize the counter to either zero or one before the while loop begins.
- If you initialized your counter to zero you will want the loop to continue as long as your counter is less than the number of grades.
- If you initialized your counter to one you will want the loop to continue as long as your counter is less than or equal to the number of grades.
- While within the body of the ELSE:
- Within the WHILE loop:
- Prompt the User for the next grade.
- Compute a running total of these grades as they are entered.
- After the WHILE Loop is done executing, compute the average of all the grades entered. Remember to check to make sure you don't perform a division by zero.
- Within the WHILE loop:
- Include all Prologue information.
- Include an initial algorithm.
- Include a refined algorithm.
NOTE 1:
- DO NOT use the "return 0" code, end, break, or exit to force an exit from within your IF/ELSE structure. Declare all variables within the data declaration section.
- Let the program progress to the end of the main function.
- The end of the main function is the only place that the return 0 should be placed.
- A SWITCH statement is the only place that the break command should be used.
- DO NOT use the "continue" statement.
NOTE 2: 1. Declare all variables within the data declaration section of each class and method. (-.1) 2 Do not get input on the same line as a variable declaration. (-.1) 3. Do not place an equation for computation on the same line as declaring a variable. (-.1)
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