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

Program should still ask the user to input a grade (integer from 1-100) and then

ID: 3550477 • Letter: P

Question

        Program should still ask the user to input a grade (integer from 1-100) and then output the letter grade.  Scale:  Greater than 90 is an "A"; Greater than 80 to 90 is a "B", Greater than 70 to 80 is a "C", Greater than 60 to 70 is a "D", and 60 or less is an "F"


Program should have :


a.       A while loop so one does not have to re-start the program with every new grade

b.      Use any score less than 0 (zero) as the sentinel to stop the while loop.

c.       You need to use If and else statements, not just If statements.

d.      Input grade and letter grade should be output to screen with each number grade input.

e.      Finally, your application will calculate and output the average grade for students input.

Explanation / Answer

//Program should still ask the user to input a grade (integer from 1-100) and then output the letter grade.
import java.util.*;
public class letterGrade
{
public static void main(String[] args)
{
int grade = 0;
double sum = 0;
int count= 0;
Scanner in = new Scanner(System.in);
//a. A while loop so one does not have to re-start the program with every new grade
System.out.println("Enter your Grade :");
grade = in.nextInt();
while(grade>=0) //b. Use any score less than 0 (zero) as the sentinel to stop the while loop.
{
sum = sum + grade;
count++;
System.out.print("Grade is "+grade+ " letter ");
//Scale: Greater than 90 is an "A"; Greater than 80 to 90 is a "B", Greater than 70 to 80 is a "C", Greater than 60 to 70 is a "D", and 60 or less is an "F"
//c. You need to use If and else statements, not just If statements.
if(grade>90)
System.out.println("Grade is A");
else if(grade>80 && grade<=90)
System.out.println("Grade is B");
else if(grade>70 && grade<=80)
System.out.println("Grade is C");
else if(grade>60 && grade<=70)
System.out.println("Grade is D");
else
System.out.println("Grade is E");
//d. Input grade and letter grade should be output to screen with each number grade input.
System.out.println("Enter your Grade :");
grade = in.nextInt();
}
double avg = sum/count;
System.out.print("Average Grade is "+avg+ " letter ");
if(avg>90)
System.out.println("Your Final average Grade is A");
else if(avg>80 && avg<=90)
System.out.println("Your Final average Grade is B");
else if(avg>70 && avg<=80)
System.out.println("Your Final average Grade is C");
else if(avg>60 && avg<=70)
System.out.println("Your Final average Grade is D");
else
System.out.println("Your Final average Grade is E");
//e. Finally, your application will calculate and output the average grade for students input.

}
}