cover picture cover picture


Homework 8

CMP 167: Programming Methods I
Lehman College, City University of New York
Spring 2016


This Homework Is Due By 11:59 PM on Sunday May 8, 2016

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:

  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 of the 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 returns the computed sum of all the grades.

    Side Effects - None.
  3. public static double averageExamGrade().

    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.

    Return Value - This method returns the computed average.

    Side Effects - None.
  4. public static int maxExamGrade().

    This method will search all the grades in the 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.
  5. public static int indexOfFirstMaxExamGrade().

    This method will search all the grades in the 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.
  6. public static int minExamGrade().

    This method will search all the grades in the 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.
  7. public static int indexOfFirstMinExamGrade().

    This method will search all the grades in the 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.
  8. public static int numberOfBelowAverageGrades().

    This method will search all the grades in the 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.
  9. public static int numberOfAboveAverageGrades().

    This method will search all the grades in the 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.
  10. public static void main(String[] args).

    This is your 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:

    • Number Of Exam Grades = numberOfGrades
    • Maximum Exam Grade = maxExamGrade() At Index = indexOfMaxExamGrade
    • Minimum Exam Grade = minExamGrade() At Index = indexOfMinExamGrade
    • Number of Below Average Exam Grades = numberOfBelowAverageGrades()
    • Number of Above Average Exam Grades = numberOfAboveAverageGrades()


    Your program will stop when you are given a list that contains no grades. In other words, when the user enter a -1 by itself.

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 :