These pictures are all the one single question. Please help, thanks. The last ou
ID: 3808513 • Letter: T
Question
These pictures are all the one single question. Please help, thanks. The last output is just a sample of what the output should look like. Your class should be named ExamGrades. You should have the following global definitions: public static final int MAX ExAM GRADES 100; public static int[J examGrades new int [MAX EXAM GRADE public static int numberofGrades; Your program will have the following methods: 1. public static int readExamGrades This method will read a list of exam grades from the user and place them into the examGrades array. The exam grades are all int values, and there will be a negative number used as a sentinel value to indicate the end of the input. (Please note that this negative number is used only to end the reading of the exam grades and it should not be used in any of your calculation. Your prompt to the user to enter a grade should be: Enter a grade: Parameters This method has no parameters, as indicated by the fact that there is nothing inside the in the method definition. Return value This method returns the number of grades that were read from the user. Side Effects In addition to changing the contents ofthe examGrades array, this method will set the global variable numberofGrades to the actual number of grades obtained from the user. 2. public static int sumofExamGrades This method will compute the sum of all the grades in the examGrades array. Parameters-This method has no parameters, as indicated by the fact that there is nothing inside the in the method definition. Return value This method retums the computed sum of all the grades. Side Effects None. 3. public static double averageExamGrade O. This method will compute the average grade of all the grades in the examGrades array. You should make use of the sumofExamGrades method in your computation Parameters This method has no parameters, as indicated by the fact that there is nothing inside the in the method definition.
Explanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static final int MAX_EXAM_GRADES = 100;
public static int[] examGrades = new int[MAX_EXAM_GRADES];
public static int numberOfGrades;
public static int readExamGrades(){
Scanner obj = new Scanner(System.in);
int x;
int ind = 0;
while((x=obj.nextInt())>=0){
examGrades[ind++] = x;
}
numberOfGrades = ind;
return ind;
}
public static int sumOfExamGrades(){
int sum = 0;
for(int i=0;i<numberOfGrades;i++){
sum+=examGrades[i];
}
return sum;
}
public static double averageExamGrade(){
return (sumOfExamGrades()*1d)/(numberOfGrades*1d);
}
public static int maxExamGrade(){
int max = -1;
for(int i=0;i<numberOfGrades;i++){
max = Math.max(max,examGrades[i]);
}
return max;
}
public static int indexOfFirstMaxExamGrade(){
int max = examGrades[0];
int ind = 0;
for(int i=1;i<numberOfGrades;i++){
if(examGrades[i]>max){
max = examGrades[i];
ind = i;
}
}
return ind;
}
public static int minExamGrade(){
int min = Integer.MAX_VALUE;
for(int i=0;i<numberOfGrades;i++){
min = Math.min(min,examGrades[i]);
}
return min;
}
public static int indexOfFirstMinExamGrade(){
int min = examGrades[0];
int ind = 0;
for(int i=1;i<numberOfGrades;i++){
if(examGrades[i]<min){
min = examGrades[i];
ind = i;
}
}
return ind;
}
public static int numberOfBelowAverageGrades(){
int ans = 0;
double avg = averageExamGrade();
for(int i=0;i<numberOfGrades;i++){
if(examGrades[i]<avg){
ans++;
}
}
return ans;
}
public static int numberOfAboveAverageGrades(){
int ans = 0;
double avg = averageExamGrade();
for(int i=0;i<numberOfGrades;i++){
if(examGrades[i]>avg){
ans++;
}
}
return ans;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
readExamGrades();
System.out.println("number of exam grades "+numberOfGrades);
System.out.println("maximum exam grade "+maxExamGrade()+" At index "+indexOfFirstMaxExamGrade());
System.out.println("minimum exam grade "+minExamGrade()+" At index "+indexOfFirstMinExamGrade());
System.out.println("number of below average exam grades "+numberOfBelowAverageGrades());
System.out.println("number of above average exam grades "+numberOfAboveAverageGrades());
}
}
OUTPUT 1 :
25 75 -1
number of exam grades 2
maximum exam grade 75 At index 1
minimum exam grade 25 At index 0
number of below average exam grades 1
number of above average exam grades 1
OUTPUT 2 :
0 10 20 30 40 50 60 70 80 90 100 -1
number of exam grades 11
maximum exam grade 100 At index 10
minimum exam grade 0 At index 0
number of below average exam grades 5
number of above average exam grades 5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.