Answered step by step
Verified Expert Solution
Link Copied!

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:

  1. 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.
  2. 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.
  3. Include all Prologue information.
  4. Include an initial algorithm.
  5. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago

Question

Question What is the doughnut hole in HSA coverage?

Answered: 1 week ago