Q:

Develop a class-averaging program that processes grades for an arbitrary number of students each time it’s run

0

Develop a class-averaging program that processes grades for an arbitrary number of students each time it’s run.

Sentinel-controlled repetition is often called indefinite repetition because the number of repetitions is not known before the loop begins executing.

A special value called a sentinel value (also called a signal value, a dummy value or a flag value) can be used to indicate “end of data entry.” 

A sentinel value must be chosen that cannot be confused with an acceptable input value. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;

public class JavaApplication28 {

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int total=0;
        int gradeCounter=0;
        System.out.print("Enter grade or -1 to quit: ");
        int grade=input.nextInt();
        while(grade != -1)
        {
            total=total+grade;
            gradeCounter=gradeCounter+1;
            System.out.print("Enter grade or -1 to quit: ");
            grade=input.nextInt();
        }
        if(gradeCounter > 0)
        {
            double average=(double)total/gradeCounter;
            System.out.printf("%nTotal of the %d grades entered is %d%n",gradeCounter, total);
            System.out.printf("Class average is %.2f%n",average);
        }
        else
            System.out.println("No grades were entered");
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now