/Users/martina/NetbeansProjects/Ercolino Workolino/src/dossier/pkgfor/ercolino/SortAndSearchErcolino.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 package dossier.pkgfor.ercolino;
 7 
 8 import java.util.ArrayList;
 9 
10 /**
11  *
12  * @author martina
13  */
14 public class SortAndSearchErcolino {
15 
16     public void allWithFrost(ArrayList<VagetableOrFruit> dossierForErcolinoList) {
17         //Declaring a new Array list to be called "VagetableOrFruit" 
18         //set to public for frost
19     
20         ArrayList<VagetableOrFruit> frostArray = new ArrayList();
21         for (int i = 0; i < dossierForErcolinoList.size(); i++) {
22             if (dossierForErcolinoList.get(i).getFrost()) {
23                 frostArray.add(dossierForErcolinoList.get(i));
24 
25             }
26         }
27         sortByHighestYield(frostArray);
28     }
29 
30     public void allWithoutFrost(ArrayList<VagetableOrFruit> dossierForErcolinoList) {
31          //Declaring a new Array list to be called "VagetableOrFruit" 
32         //set to public for withoutfrost
33         ArrayList<VagetableOrFruit> notFrostArray = new ArrayList();
34         for (int i = 0; i < dossierForErcolinoList.size(); i++) {
35             if (dossierForErcolinoList.get(i).getFrost()) {
36                 notFrostArray.add(dossierForErcolinoList.get(i));
37 
38             }
39         }
40         sortByHighestYield(notFrostArray);
41     }
42 
43     public void sortByHighestYield(ArrayList<VagetableOrFruit> dossierForErcolinoList) {
44         int n = dossierForErcolinoList.size();
45         boolean sorted = false;
46         while (!sorted) {
47 
48             n--;
49             sorted = true;
50 
51             for (int i = 0; i < n; i++) {
52                 if (dossierForErcolinoList.get(i).getAmountOfYield() >dossierForErcolinoList.get(i).getAmountOfYield()) {
53 
54                     VagetableOrFruit temp = dossierForErcolinoList.get(i);
55                     //making temporary carList object
56                     dossierForErcolinoList.set(i, dossierForErcolinoList.get(i + 1));
57                     //set the first to be the second
58                     dossierForErcolinoList.set(i + 1, temp);
59                     //set the second to be the temp
60                     sorted = false;
61 
62                 }
63             }
64         }
65     }//
66 }//
67