Question

In: Computer Science

AverageGrade. Assume the professor gives five exams during the semester with grades 0 through 100 and...

AverageGrade. Assume the professor gives five exams during the semester with grades 0 through 100 and drops one of the exams with the lowest grade. Write a program to find the average of the remaining four grades. The program should use a class named Exams that has 1. An instance variable to hold a list of five grades, 2. A method that calculate and return average. 3. A string that return the “exams Average” for printing. Your program output should prompt for an input for each grade. Use any number between 0 and 100. Your submission should include compiled output.

use java

Solutions

Expert Solution

Code:

import java.util.*; 
import java.util.Scanner;
class Exams{ 
    public static int grades[]=new int[5];   //it is instance variable of class to holds grades 
    public static double avarage=0;
    public static double calavg(int[] g){  
        double sum=0;
        Arrays.sort(g);     //short the grades because we dont want to calculate avarage of lowest grade 
        for(int i = 1; i < 5; i++)  //so here lowest grade is present at 0th index in grade array so we start from 1 
        {
            sum+=g[i];    //it calculate sum of all grades excluding lowest grade
        }
        avarage=sum/4;    //calculate avarage of grades excluding lowest grade
        return avarage;
    }  
    public static String print()    //return string with avarage
    {
        return "Your avarage of grades excluding lowest grade is : "+avarage;
    }
    public static void main(String args[]){  
        
        Scanner s = new Scanner(System.in);
        System.out.print("Enter your 5 grades from 0 to 100 :\n");

        for(int i = 0; i < 5; i++)  //it will take 5 grades from user
        {
            grades[i] = s.nextInt();  //store 5 grades into array
        }
        calavg(grades);    //call function to calculate avarage of grades
        System.out.print(print());   //print avarage of grdes
    }
}

Output:


Related Solutions

M12 Q21 Professor Gill has taught General Psychology for many years. During the semester, she gives...
M12 Q21 Professor Gill has taught General Psychology for many years. During the semester, she gives three multiple-choice exams, each worth 100 points. At the end of the course, Dr. Gill gives a comprehensive final worth 200 points. Let x1, x2, and x3 represent a student's scores on exams 1, 2, and 3, respectively. Let x4 represent the student's score on the final exam. Last semester Dr. Gill had 25 students in her class. The student exam scores are shown...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a...
Professor Fair believes that extra time does not improve grades on exams. He randomly divided a group of 300 students into two groups and gave them all the same test. One group had exactly 1 hour in which to finish the test, and the other group could stay as long as desired. The results are shown in the following table. Test at the 0.01 level of significance that time to complete a test and test results are independent. Time A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT