/Users/adamklas/Desktop/IB/Net Beans/Dossier for Ms. Boughey/src/dossier/pkgfor/ms/boughey/Averages.java
  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 
  7 package dossier.pkgfor.ms.boughey;
  8 
  9 import java.util.ArrayList;
 10 import java.util.Calendar;
 11 
 12 
 13 
 14 /**
 15  *
 16  * @author adamklas
 17  */
 18 public class Averages {
 19     
 20             //The method for finding the average of a Class
 21     public double classAverage(ArrayList<Student> studentList, String classToSearchFor, String category){
 22         //Here the Array List of students gets sorted
 23         //refer to SortAndSearch.java, lines 18-47 for description
 24         int n = studentList.size();
 25         boolean sorted = false;
 26         while (!sorted) {
 27             n--;
 28             sorted = true;
 29             for (int i = 0; i < n; i++) {
 30                 if (studentList.get(i).getStudentBlock().compareTo(studentList.get(i + 1).getStudentBlock()) > 0) {
 31                     Student temp = studentList.get(i); //making a temporary carList object
 32                     studentList.set(i, studentList.get(i + 1)); //set first to be the second
 33                     studentList.set(i + 1, temp);//set the second to be the temp
 34                     sorted = false;
 35 
 36                 }
 37             }
 38         }
 39         //Here I create an empty Array List of Students
 40         ArrayList<Student> blockToSearchList = new ArrayList();
 41 
 42        //Here I loop through the Array List of Students
 43         for (int i = 0; i < studentList.size(); i++) {
 44             //If the class of the Student matches the class selected by the user then...
 45             if (studentList.get(i).getStudentBlock().equals(classToSearchFor)) {
 46                 //The Student gets added to the selection Array List, created before
 47                 blockToSearchList.add(studentList.get(i));
 48             }
 49         }
 50         
 51         //Here I make an instance of my bestTrial class
 52         BestTrial bestTrial = new BestTrial();
 53         //the Double "average" is set established, and set to be an error
 54         double average = -1;
 55         //This code happens if the category Shotput is selected
 56         if(category.equals("Shotput")){
 57             //Integer sum is set to be zero by default
 58             int sum = 0;
 59             //Here I loop through the selection Array List
 60         for(int i = 0; i < blockToSearchList.size(); i++){
 61             //the Best Trial of each Student is addded to the sum
 62             sum += bestTrial.bestTrialDistance(blockToSearchList.get(i).getShotPut1(), blockToSearchList.get(i).getShotPut2(), blockToSearchList.get(i).getShotPut3());
 63         }
 64         //Here the sum is divide by the number of Students selected
 65         //This gives the average of the scores
 66         average = sum/ blockToSearchList.size();
 67         
 68     }
 69         //This code for all the categories is the same (except the 1.5k run, lines 114-118)
 70         //refer to lines 56 - 68 for description
 71     else if(category.equals("Javelin")){
 72     int sum = 0;
 73         for(int i = 0; i < blockToSearchList.size(); i++){
 74             sum += sum += bestTrial.bestTrialDistance(blockToSearchList.get(i).getJavelin1(), blockToSearchList.get(i).getJavelin2(), blockToSearchList.get(i).getJavelin3());
 75         }
 76         
 77         average = sum/ blockToSearchList.size();
 78         
 79 }else if(category.equals("Discuss")){
 80     int sum = 0;
 81         for(int i = 0; i < blockToSearchList.size(); i++){
 82             sum += bestTrial.bestTrialDistance(blockToSearchList.get(i).getDiscuss1(), blockToSearchList.get(i).getDiscuss2(), blockToSearchList.get(i).getDiscuss3());
 83         }
 84         
 85         average = sum/ blockToSearchList.size();
 86         
 87 }else if(category.equals("Long Jump")){
 88     int sum = 0;
 89         for(int i = 0; i < blockToSearchList.size(); i++){
 90             sum += bestTrial.bestTrialDistance(blockToSearchList.get(i).getLongJump1(), blockToSearchList.get(i).getLongJump2(), blockToSearchList.get(i).getLongJump3());
 91         }
 92         
 93         average = sum/ blockToSearchList.size();
 94         
 95 }else if(category.equals("60 meter run")){
 96     int sum = 0;
 97         for(int i = 0; i < blockToSearchList.size(); i++){
 98             sum += bestTrial.bestTrialTimeSeconds(blockToSearchList.get(i).getSixtyMeter1().get(Calendar.SECOND), blockToSearchList.get(i).getSixtyMeter2().get(Calendar.SECOND));
 99         }
100         
101         average = sum/ blockToSearchList.size();
102         
103 }else if(category.equals("200 meter run")){
104     int sum = 0;
105         for(int i = 0; i < blockToSearchList.size(); i++){
106             sum += bestTrial.bestTrialTimeSeconds(blockToSearchList.get(i).getTwoHundredMeter1().get(Calendar.SECOND), blockToSearchList.get(i).getTwoHundredMeter2().get(Calendar.SECOND));
107         }
108         
109         average = sum/ blockToSearchList.size();
110         
111 }else if(category.equals("1,500 meter run")){
112     int sum = 0;
113         for(int i = 0; i < blockToSearchList.size(); i++){
114             //Here the total seconds of both trials are calculated
115             int totalSec1 = (((blockToSearchList.get(i).getOneK500Meter1().get(Calendar.MINUTE)*60) + blockToSearchList.get(i).getOneK500Meter1().get(Calendar.SECOND)));
116             int totalSec2 = (((blockToSearchList.get(i).getOneK500Meter2().get(Calendar.MINUTE)*60) + blockToSearchList.get(i).getOneK500Meter2().get(Calendar.SECOND)));
117             //Then the total seconds are compared for the Best Trial 
118             sum += bestTrial.bestTrialTimeSeconds(totalSec1, totalSec2);
119         }
120         
121         average = sum/ blockToSearchList.size();
122         
123 }
124         //The average found is returned
125         return average;
126       
127     }
128             //The method for finding the average of a Class
129             //This is the same as the method for classes
130             //Therefore refer to lines 21 - 70 for description
131     public double yearAverage(ArrayList<Student> studentList, String yearToSearchFor, String category){
132         int n = studentList.size();
133         boolean sorted = false;
134         while (!sorted) {
135             n--;
136             sorted = true;
137             for (int i = 0; i < n; i++) {
138                 if (studentList.get(i).getStudentYear().compareTo(studentList.get(i + 1).getStudentYear()) > 0) {
139                     Student temp = studentList.get(i); //making a temporary carList object
140                     studentList.set(i, studentList.get(i + 1)); //set first to be the second
141                     studentList.set(i + 1, temp);//set the second to be the temp
142                     sorted = false;
143 
144                 }
145             }
146         }
147         //find the chosen class
148         ArrayList<Student> yearToSearchList = new ArrayList();
149 
150        
151         int counter = 0;
152         for (int i = 0; i < studentList.size(); i++) {
153             if (studentList.get(i).getStudentYear().equals(yearToSearchFor)) {
154                 yearToSearchList.add(studentList.get(i));
155             }
156         }
157         
158         BestTrial bestTrial = new BestTrial();
159         double average = -1;
160         if(category.equals("Shotput")){
161             int sum = 0;
162         for(int i = 0; i < yearToSearchList.size(); i++){
163             sum += bestTrial.bestTrialDistance(yearToSearchList.get(i).getShotPut1(), yearToSearchList.get(i).getShotPut2(), yearToSearchList.get(i).getShotPut3());
164         }
165         
166         average = sum/ yearToSearchList.size();
167         
168     }
169     else if(category.equals("Javelin")){
170     int sum = 0;
171         for(int i = 0; i < yearToSearchList.size(); i++){
172             sum += sum += bestTrial.bestTrialDistance(yearToSearchList.get(i).getJavelin1(), yearToSearchList.get(i).getJavelin2(), yearToSearchList.get(i).getJavelin3());
173         }
174         
175         average = sum/ yearToSearchList.size();
176         
177 }else if(category.equals("Discuss")){
178     int sum = 0;
179         for(int i = 0; i < yearToSearchList.size(); i++){
180             sum += bestTrial.bestTrialDistance(yearToSearchList.get(i).getDiscuss1(), yearToSearchList.get(i).getDiscuss2(), yearToSearchList.get(i).getDiscuss3());
181         }
182         
183         average = sum/ yearToSearchList.size();
184         
185 }else if(category.equals("Long Jump")){
186     int sum = 0;
187         for(int i = 0; i < yearToSearchList.size(); i++){
188             sum += bestTrial.bestTrialDistance(yearToSearchList.get(i).getLongJump1(), yearToSearchList.get(i).getLongJump2(), yearToSearchList.get(i).getLongJump3());
189         }
190         
191         average = sum/ yearToSearchList.size();
192         
193 }else if(category.equals("60 meter run")){
194     int sum = 0;
195         for(int i = 0; i < yearToSearchList.size(); i++){
196             sum += bestTrial.bestTrialTimeSeconds(yearToSearchList.get(i).getSixtyMeter1().get(Calendar.SECOND), yearToSearchList.get(i).getSixtyMeter2().get(Calendar.SECOND));
197         }
198         
199         average = sum/ yearToSearchList.size();
200         
201 }else if(category.equals("200 meter run")){
202     int sum = 0;
203         for(int i = 0; i < yearToSearchList.size(); i++){
204             sum += bestTrial.bestTrialTimeSeconds(yearToSearchList.get(i).getTwoHundredMeter1().get(Calendar.SECOND), yearToSearchList.get(i).getTwoHundredMeter2().get(Calendar.SECOND));
205         }
206         
207         average = sum/ yearToSearchList.size();
208         
209 }else if(category.equals("1,500 meter run")){
210     int sum = 0;
211         for(int i = 0; i < yearToSearchList.size(); i++){
212             int totalSec1 = (((yearToSearchList.get(i).getOneK500Meter1().get(Calendar.MINUTE)*60) + yearToSearchList.get(i).getOneK500Meter1().get(Calendar.SECOND)));
213             int totalSec2 = (((yearToSearchList.get(i).getOneK500Meter2().get(Calendar.MINUTE)*60) + yearToSearchList.get(i).getOneK500Meter2().get(Calendar.SECOND)));
214             sum += bestTrial.bestTrialTimeSeconds(totalSec1, totalSec2);
215         }
216         
217         average = sum/ yearToSearchList.size();
218         
219 }
220         return average;
221            
222         
223     }
224 }
225     
226 
227