/Users/johnr/Desktop/IA Submissions/IA Final Submission 000307-0023 - Jimmy/Product/ProductDataBase/src/ProductDataBase/SortandSearchClass.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 ProductDataBase;
  7 
  8 /**
  9  *
 10  * @author 15417
 11  */
 12 public class SortandSearchClass
 13 {
 14 
 15     // sort and search class for product array. Sorts by model number of product.
 16     public void selectionSortOfProductModel(Product[] productArray, int Productcounter)
 17     {
 18         for (int min = 0; min < Productcounter; min++)
 19         {
 20             int minIndex = min;      // Assumed index of smallest remaining value.
 21             for (int j = min + 1; j < Productcounter; j++)
 22             {
 23                 if (productArray[j].getModelNumber() < productArray[minIndex].getModelNumber())
 24                 {
 25                     minIndex = j;  // Remember index of new minimum
 26                 }
 27 
 28                 if (minIndex != min)
 29                 {
 30                     //Exchange current element with smallest remaining.
 31                     //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 32                     Product temp = productArray[min];
 33                     productArray[min] = productArray[minIndex];
 34                     productArray[minIndex] = (temp);
 35                 }
 36             }
 37         }
 38     }
 39     //sort and search for purchaseOrderArray (sorts by purchase order number)
 40     public void selectionSortOfPurchaseOrderByOrderNumber(PurchaseOrder[] purchaseOrderArray, int Ordercounter)
 41     {
 42     for (int min = 0; min < Ordercounter; min++)
 43         {
 44             int minIndex = min;      // Assumed index of smallest remaining value.
 45             for (int j = min + 1; j < Ordercounter; j++)
 46             {
 47                 if (purchaseOrderArray[j].getPurchaseOrderNumber() < purchaseOrderArray[minIndex].getPurchaseOrderNumber())
 48                 {
 49                     minIndex = j;  // Remember index of new minimum
 50                 }
 51 
 52                 if (minIndex != min)
 53                 {
 54                     //Exchange current element with smallest remaining.
 55                     //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 56                     PurchaseOrder temp = purchaseOrderArray[min];
 57                     purchaseOrderArray[min] = purchaseOrderArray[minIndex];
 58                     purchaseOrderArray[minIndex] = (temp);
 59                 }
 60             }
 61         }
 62     }
 63     
 64     public void selectionSortOfPurchaseOrderByModelNumber(PurchaseOrder[] purchaseOrderArray, int Ordercounter)
 65     {
 66     for (int min = 0; min < Ordercounter; min++)
 67         {
 68             int minIndex = min;      // Assumed index of smallest remaining value.
 69             for (int j = min + 1; j < Ordercounter; j++)
 70             {
 71                 if (purchaseOrderArray[j].getModelNumber() < purchaseOrderArray[minIndex].getModelNumber())
 72                 {
 73                     minIndex = j;  // Remember index of new minimum
 74                 }
 75 
 76                 if (minIndex != min)
 77                 {
 78                     //Exchange current element with smallest remaining.
 79                     //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
 80                     PurchaseOrder temp = purchaseOrderArray[min];
 81                     purchaseOrderArray[min] = purchaseOrderArray[minIndex];
 82                     purchaseOrderArray[minIndex] = (temp);
 83                 }
 84             }
 85         }
 86     }
 87     
 88     public void selectionSortOfPurchaseOrderByOrderID(PurchaseOrder[] purchaseOrderArray, int Ordercounter)
 89     {
 90     for (int min = 0; min < Ordercounter; min++)
 91         {
 92             int minIndex = min;      // Assumed index of smallest remaining value.
 93             for (int j = min + 1; j < Ordercounter; j++)
 94             {
 95                 if (purchaseOrderArray[j].getPurchaseOrderID() < purchaseOrderArray[minIndex].getPurchaseOrderID())
 96                 {
 97                     minIndex = j;  // Remember index of new minimum
 98                 }
 99 
100                 if (minIndex != min)
101                 {
102                     //Exchange current element with smallest remaining.
103                     //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
104                     PurchaseOrder temp = purchaseOrderArray[min];
105                     purchaseOrderArray[min] = purchaseOrderArray[minIndex];
106                     purchaseOrderArray[minIndex] = (temp);
107                 }
108             }
109         }
110     }
111 }
112