SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2.  
  3. public class GradeAnalyzer {
  4.   public GradeAnalyzer() {
  5.    
  6.   }
  7.  
  8.   public int getAverage(ArrayList<Integer> grades) {
  9.     if (grades.size() < 1) {
  10.       System.out.println("Error: the ArrayList is empty!");
  11.       return 0;
  12.     }
  13.     else {
  14.       int sum = 0;
  15.      
  16.       for (int grade: grades) {
  17.         sum += grades;
  18.        
  19.       }
  20.       int average = sum / grades.size();
  21.      
  22.       System.out.println(average);
  23.      
  24.       return average;
  25.     }
  26.   }
  27.   public static void main (String[] args) {
  28.    
  29.     ArrayList<Integer> myClassroom = new ArrayList<Integer>();
  30.     myClassroom.add(98);
  31.     myClassroom.add(92);
  32.     myClassroom.add(88);
  33.     myClassroom.add(75);
  34.     myClassroom.add(61);
  35.     myClassroom.add(89);
  36.     myClassroom.add(95);
  37.    
  38.     gradeAnalyzer myAnalyzer = new gradeAnalyzer();
  39.    
  40.     myAnalyzer.getAverage(myClassroom);
  41.    
  42.   }
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top