In your textbook, this homework problem is in section 6.15 Homework 8-1.
So far in this course, all of your programs have been written to be fully contained
inside a single method named main. The main method
is where Java begins execution of your program. In this assignment,
you will coding other methods in addition to the main method. These
additional methods will perform specific funtions and, in most cases, return results.
This assignment is similar, but not identical, to the GradesArray assignment that you did in Homework 7-1.
Your class should be named ExamGrades.
You should have the following global definitions:
public static final int MAX_EXAM_GRADES = 100;
public static int[] examGrades = new int[MAX_EXAM_GRADES];
public static int numberOfGrades;
Your program will have the following methods:
public static int readExamGrades().
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 of the examGrades
array, this method will set the global variable numberOfGrades
to the actual number of grades obtained from the user.
public static int sumOfExamGrades().
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 returns the computed sum of all the grades.
Side Effects - None.
public static double averageExamGrade().
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.
Return Value - This method returns the computed average.
Side Effects - None.
public static int maxExamGrade().
examGrades array for the
highest 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 highest grade of all the grades.
Side Effects - None.
public static int indexOfFirstMaxExamGrade().
examGrades array for the
index of the first occurrence of the highest 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 index of the first occurrence of the
highest grade of all the grades.
Side Effects - None.
public static int minExamGrade().
examGrades array for the
lowest 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 lowest grade of all the grades.
Side Effects - None.
public static int indexOfFirstMinExamGrade().
examGrades array for the
index of the first occurence of the lowest 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 index of the first occurrence of the
lowest grade of all the grades.
Side Effects - None.
public static int numberOfBelowAverageGrades().
examGrades array and compute
the number of grades that are below average.
You should make use of the averageExamGrade() 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.
Return Value - This method returns the number of grades that are below average.
Side Effects - None.
public static int numberOfAboveAverageGrades().
examGrades array and compute
the number of grades that are above average.
You should make use of the averageExamGrade() 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.
Return Value - This method returns the number of grades that are above average.
Side Effects - None.
public static void main(String[] args).
main main method and where your program begins execution. For
this assignment, you will be reading in multiple lists of exam grades. for each of the
lists you will display the following information:
For example, if the input is:
25 75 -1
0 10 20 30 40 50 60 70 80 90 100 -1
19 15 14 33 76 46 88 78 69 79 75 73 72 -1
-1
The output will be:
Enter a grade :
Enter a grade :
Enter a grade :
Number Of 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
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Number Of 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
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Number Of Grades = 13
Maximum Exam Grade = 88 At Index = 6
Minimum Exam Grade = 14 At Index = 2
Number Of Below Average Exam Grades = 5
Number Of Above Average Exam Grades = 8
Enter a grade :