Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Intro to Computing: Write a program to read a list of exam scores given as integ

ID: 3772904 • Letter: I

Question

Intro to Computing:

Write a program to read a list of exam scores given as integer percentages in the range 0 to 100. Display the total number of grades and the number of grades in each letter-grade category as follows: 90-100 is an A, 80-89 is a B, 70-79 is a C, 60-69 is a D, and 0-59 is an F. Print the percentage of the total for each letter grade, the lowest grade, the highest grade, and the average grade. Use a negative score as a sentinel value to indicate the end of the output.

For example if the input is:

98, 87, 86, 85, 85, 78, 73, 72, 72, 70, 66, 63, 50, -1

the output would be:

Total number of grades was 13

Number of A's = 1, Number of B's = 4, Number of C's = 5, Number of D's = 2, Number of F's = 1

Percentage of A's = 7.69%, B's = 30.77%, C's = 38.46%, D's = 15.38%, F's = 7.69%

The smallest is 50, the largest is 98

Explanation / Answer

import java.util.Scanner;

/**
* @author Srinivas Palli
*
*/
public class GradesCaliculation {

   /**
   * @param args
   */
   public static void main(String[] args) {

       Scanner scanner;
       try {
           scanner = new Scanner(System.in);
           System.out.print("Enter the Grades:");
           String grades = scanner.nextLine();
           int maxGrade, minGrade, noofA = 0, noofB = 0, noofC = 0, noofD = 0, noofF = 0;
           String gradesArr[] = grades.split(", ");
           int noOfGrades = gradesArr.length - 1;
           System.out.println("Total number of grades was " + noOfGrades);
           maxGrade = minGrade = Integer.parseInt(gradesArr[0]);
           for (int i = 0; i < gradesArr.length - 1; i++) {
               int grade = Integer.parseInt(gradesArr[i]);
               // System.out.println(gradesArr[i]);

               if (grade >= 90 && grade <= 100) {
                   noofA++;

               } else if (grade >= 80 && grade <= 89) {
                   noofB++;

               } else if (grade >= 70 && grade <= 79) {
                   noofC++;

               } else if (grade >= 60 && grade <= 69) {
                   noofD++;

               } else if (grade >= 0 && grade <= 59) {
                   noofF++;

               }

               if (maxGrade < grade) {

                   maxGrade = grade;
               }
               if (minGrade > grade) {

                   minGrade = grade;
               }

           }

           System.out.println("Number of A's =" + noofA);
           System.out.println("Number of B's =" + noofB);
           System.out.println("Number of C's =" + noofC);
           System.out.println("Number of D's =" + noofD);
           System.out.println("Number of F's =" + noofF);

           System.out.printf("Percentage of A's = %.2f%s ",
                   (((double) noofA / (double) noOfGrades) * 100.00), "%");
           System.out.printf("Percentage of B's = %.2f%s ",
                   (((double) noofB / (double) noOfGrades) * 100.00), "%");
           System.out.printf("Percentage of C's = %.2f%s ",
                   (((double) noofC / (double) noOfGrades) * 100.00), "%");
           System.out.printf("Percentage of D's = %.2f%s ",
                   (((double) noofD / (double) noOfGrades) * 100.00), "%");
           System.out.printf("Percentage of F's = %.2f%s ",
                   (((double) noofF / (double) noOfGrades) * 100.00), "%");

           System.out.println("The smallest is " + minGrade);
           System.out.println("the largest is " + maxGrade);

       } catch (Exception e) {
           // TODO: handle exception
       }

   }
}

OUTPUT:

Enter the Grades:98, 87, 86, 85, 85, 78, 73, 72, 72, 70, 66, 63, 50, -1
Total number of grades was 13
Number of A's =1
Number of B's =4
Number of C's =5
Number of D's =2
Number of F's =1
Percentage of A's = 7.69%
Percentage of B's = 30.77%
Percentage of C's = 38.46%
Percentage of D's = 15.38%
Percentage of F's = 7.69%
The smallest is 50
the largest is 98

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote