Grades - numStudents = 0; numPass = 0; numFail = 0; // Read...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// *************************************************************** // Grades.java // // Read in a sequence of grades and compute the average // grade, the number of passing grades (at least 60) // and the number of failing grades. // *************************************************************** import java.util.Scanner; public class Grades { public static void main (String[] args) { double grade; // a student's grade double sumOfGrades; // a running total of the student grades int numStudents; // a count of the students int numPass; // a count of the number who pass int numFail; // a count of the number who fail Scanner scan = new Scanner (System.in); System.out.println ("\nGrade Processing Program\n"); // Initialize summing and counting variables sumOfGrades = 0;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: numStudents = 0; numPass = 0; numFail = 0; // Read in the first grade System.out.print ("Enter the first student's grade: "); grade = scan.nextDouble(); while (grade >= 0) { sumOfGrades += grade; numStudents++; numFail = (grade < 60) ? numFail+1 : numFail; numPass = (grade >= 60) ? numPass+1 : numPass; // Read the next grade System.out.print ("Enter the next grade (a negative to quit): "); grade = scan.nextDouble(); } if (numStudents > 0) { System.out.println ("\nGrade Summary: "); System.out.println ("Class Average: " + sumOfGrades/numStudents); System.out.println ("Number of Passing Grades: " + numPass); System.out.println ("Number of Failing Grades: " + numFail); } else System.out.println ("No grades processed."); } }...
View Full Document

Ask a homework question - tutors are online