Program SHOULD be used in RAPTOR in INTERMEDIATE MODE. For this program, you wil
ID: 3597725 • Letter: P
Question
Program SHOULD be used in RAPTOR in INTERMEDIATE MODE.
For this program, you will calculate a student's average for a semester. The student has earned 6 test grades during the semester, and their average is calculated after removing the lowest grade from the scores. Write a program that asks the user to enter the six grades and stores them in an array. Then, search the array for the lowest value and remove that value from the total. Calculate the student's average for the best 5 grades. HINT: To find the average, the simplest approach is to find the sum of all 6 test scores and then subtract the lowest score from that total...this will give you the sum of the 5 highest test scores. When you are finding the average, don't forget to use SIZE -1 for the divisor
Example Output:
Enter grade #1
100[Enter]
Enter grade #2
90[Enter]
Enter grade #3
95[Enter]
Enter grade #4
98[Enter]
Enter grade #5
88[Enter]
Enter grade #6
92[Enter]
The low grade of 88 was dropped resulting in an average of 95
Explanation / Answer
import java.util.Scanner;
public class StudentSemester {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int SIZE = 6,MAX_SCORE = 100;
int lowest_score = MAX_SCORE + 1,total_score = 0;
int scores[] = new int[SIZE];
//taking six grades as input
System.out.println("Enter the student's six grades:");
for(int i=0;i<SIZE;i++)
scores[i] = sc.nextInt();
//calculating total and finding lowest score
for(int i=0;i<SIZE;i++){
if(scores[i] <lowest_score)
lowest_score = scores[i];
total_score += scores[i];
}
System.out.println("Lowest grade is: "+lowest_score);
total_score = total_score - lowest_score;
float avg_score = (total_score)/SIZE-1;
System.out.println("student's average for the best 5 grades: "+avg_score);
}
}
Sample Input and Output:
Enter the student's six grades:
65 58 43 79 83 90
Lowest grade is: 43
student's average for the best 5 grades: 61.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.