Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that reads a list of exam grades entered as int 's in the range of 0 to 100 . The program must



Write a program that reads a list of exam grades entered asint's in the range of0 to100. The program must report the total number of grades and the number of grades in each letter-grade category, where the letter-grade categories are as follows:

A 93 <= grade <= 100

A- 90 <= grade < 93

B+ 87 <= grade < 90

B 83 <= grade < 87

B- 80 <= grade < 83

C+ 77 <= grade < 80

C 73 <= grade < 77

C- 70 <= grade < 73

D 60 <= grade < 70

F 0 <= grade < 60

The program must use a negative number as a sentinel value to indicate the end of the input.

By definition the negative sentinel value is used only to end the loop. Do not use it in the calculations.

The program will prompt the user to enter each grade individually by printing:

Enter a grade:

If the inputs are:

98 95 87 86 83 92 85 78 74 72 81 71 69 63 50 43 -1

The output would be:

Total number of grades = 16 Number of A's = 2 Number of A-'s = 1 Number of B+'s = 1 Number of B's = 3 Number of B-'s = 1 Number of C+'s = 1 Number of C's = 1 Number of C-'s = 2 Number of D's = 2 Number of F's = 2

Please note that your class should be namedGrades.


What my code was:


 import java.util.ArrayList; import java.util.Scanner; public class Grades { public static void main(String[] args) { ArrayList list_grade = new ArrayList<>(); int[] count_grade = new int[10]; int grade; Scanner scan = new Scanner(System.in); while(true) { System.out.print("Enter a grade: "); grade = scan.nextInt(); if(grade < 0) break; list_grade.add(grade); } for (int i = 0; i < list_grade.size();i++) { grade = list_grade.get(i); if( grade >= 93 && grade <= 100) count_grade[0] += 1; else if( grade >= 90 && grade < 93) count_grade[1] += 1; else if( grade >= 87 && grade < 90) count_grade[2] += 1; else if( grade >= 83 && grade < 87) count_grade[3] += 1; else if( grade >= 80 && grade < 83) count_grade[4] += 1; else if( grade >= 77 && grade < 80) count_grade[5] += 1; else if( grade >= 73 && grade < 77) count_grade[6] += 1; else if( grade >= 70 && grade < 73) count_grade[7] += 1; else if( grade >= 60 && grade < 70) count_grade[8] += 1; else count_grade[9] += 1; } System.out.println("Total number of grades = " + list_grade.size()); System.out.println("Number of A's = " + count_grade[0]); System.out.println("Number of A-'s = " + count_grade[1]); System.out.println("Number of B+'s = " + count_grade[2]); System.out.println("Number of B's = " + count_grade[3]); System.out.println("Number of B-'s = " + count_grade[4]); System.out.println("Number of C+'s = " + count_grade[5]); System.out.println("Number of C's = " + count_grade[6]); System.out.println("Number of C-'s = " + count_grade[7]); System.out.println("Number of D's = " + count_grade[8]); System.out.println("Number of F's = " + count_grade[9]); } }

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions