Hello,
I've worked on some code for a project I have to do but I'm a little unsure about a few parts that I was hoping somebody could provide some clarity on. Here is the project that I'm working on with the code and question on it to follow:
Write a program to read a list of exam scores given as integer percentages in the range of 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
0-59 is a F
Use a negative score as a sentinel value to indicate the end of the input. The negative value is used only to end the loop, so do not use it in the calculations.
The output example:
Total number of grades = 8
Number of A's =4
Number of B's = 4
Here is what I have so far:
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
String gradeS;
char grade;
Final int SENTINEL = -1;
File inputFile = new File ( "input.txt");
Scanner scan = new scanner ( inputFile );
While ( != SENTINEL )
switch (grade)
{
case 'A':
break;
case 'B':
break;
case 'C':
break;
case 'D':
break;
case 'F':
break;
System.out.println ( "Total number of grades = " + )
System.out.println ( "Number of A's = " + )
System.out.println ( "Number of B's = " + )
I know that my code is far from complete but this is what I was able to get through so far. I'm fairly sure that I need to put a counter at the beginning when I declare my variables and then implement that counter within the switch statement to add the number of grades, but I'm unsure how to declare that and implement it. I also think I may need an if statement within the switch statement... something like case 'A'
if ( 90-100)
else
case 'B'
if (80-89)
etc.....
I appreciate any guidance that can be provided on helping me move forward on this. Thanks again.
case 'b'