Write a Java program to determine a student\'s grade. It reads three test scores
ID: 3588618 • Letter: W
Question
Write a Java program to determine a student's grade. It reads three test scores (between 0 and 100) and calculates the average score and converts it to a letter grade.
Average Score Calculation: Average Score = (Test Score 1 + Test Score 2 + Test Scores 3) /3.0
Grade Conversion Rules: Rule a. If the average score is 90 or more the grade is 'A'.
Rule b. If the average score is 70 or more and less than 90 then check the third test score. If the third score is 90 or more the grade is 'A' otherwise the grade is 'B'.
Rule c. If the average score is 50 or more and less than 70 then check the average of the second and third scores. If the average of the last two is 70 or more, the grade is 'C' otherwise it is a 'D'
Rule d. If the average score is less than 50 then the grade is 'F'.
Rounding Rule: Midpoint Rounding Calculate the grade average as a double. Round up to the next int if the fractional part is .5 or greater, otherwise truncate the fraction by casting to an int. The algorithm is: Add .5 to the average and cast the result to an int. Example: average = (int)(average+0.5);
Create a new project in NetBeans or any Java IDE, name it FirstName_LastName_A3 where FirstName is your first name and LastName is your last name. Submit your zipped project folder in Eagle Online Canvas for grading.
To solve this problem, we can identify IPO and develop the Pseudocode.
1. Input: three test scores
2. Processing: Calculate the average and convert it to letter grade according to the three conversion rules.
3. Output: Display the letter grade
4. Variables: int test1, test2, test2 – double average, average2 – char letterGrade
5. Constants: none
Detailed Pseudocode:
1. Prompt user to enter first test score
2. Read user input and store value into variable test1
3. Prompt user to enter second test score
4. Read user input and store value into the variable test2
5. Prompt user to enter third test score
6. Read user input and store value into the variable test3
7. average = (test1 + test2 + test3) / 3.0
average = (int) (average +0.5) //apply rounding rule
8. average2 = (test2+test3) / 2.0
average2 = (int) (average2+0.5) //apply rounding rule
9. if (average >=90)
letterGrade=’A’
else if (average >=70)
if (test3 >= 90)
letterGrade=’A’
else
letterGrade=’B’
else if (average >=50)
if (average2>=70)
letterGrade=’C’
else
letterGrade=’D’
else
letterGrade=’F’
10. Display letterGrade
Once the above detailed pseudocode is developed, you can map it line by line into Java code.
Explanation / Answer
package org.students;
import java.util.Scanner;
public class CalStudentGrade {
public static void main(String[] args) {
//Declaring variables
int test1, test2, test3;
double average, average2;
char letterGrade;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Getting the first score entered by the user
System.out.print("Enter first test score :");
test1 = sc.nextInt();
//Getting the second score entered by the user
System.out.print("Enter second test score :");
test2 = sc.nextInt();
//Getting the third score entered by the user
System.out.print("Enter third test score :");
test3 = sc.nextInt();
//Calculating the average
average = (test1 + test2 + test3) / 3.0;
average = (int)(average + 0.5);
//Calculating the second average
average2 = (test2 + test3) / 2.0;
average2 = (int)(average2 + 0.5);
//Calculating the letter grade based on average
if (average >= 90) {
letterGrade = 'A';
} else if (average >= 70) {
if (test3 >= 90)
letterGrade = 'A';
else
letterGrade = 'B';
} else if (average >= 50) {
if (average2 >= 70)
letterGrade = 'C';
else
letterGrade = 'D';
} else {
letterGrade = 'F';
}
//Displaying the output
System.out.println("The Grade Letter is :" + letterGrade);
}
}
____________________
Output:
Enter first test score :78
Enter second test score :87
Enter third test score :92
The Grade Letter is :A
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.