Advertisement
scaawt

BoxManager

Oct 24th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. /**
  2.  * written by tariq scott
  3.  */
  4. public class BoxManager {
  5.  
  6.   //attributes
  7.  private Box[] boxes;
  8.  public static final int DEF_SIZE = 100;//"the magic number"
  9.  //constructors
  10.  public BoxManager()//my default constructor
  11.  {
  12.   boxes = new Box[DEF_SIZE];
  13.  }
  14.  
  15.  public BoxManager(int aSize)
  16.  {
  17.   if(aSize>0)
  18.   {
  19.    boxes = new Box[aSize];
  20.   }
  21.  }
  22.  
  23.  public void addBox(Box aBox)
  24.  {
  25.   for(int i = 0; i<boxes.length; i++)
  26.   {
  27.    if(boxes[i] == null)
  28.    {
  29.     boxes[i]=aBox;
  30.     break;
  31.    }
  32.   }
  33.  }
  34. }
  35.  
  36. // public void sortBox()
  37. // {
  38. //  boolean hasSwapped = true;
  39. //  while(hasSwapped)
  40. //  {
  41. //   hasSwapped = false;
  42. //   for(int i = 0; i<boxes.length-1; i++)
  43.  //  {
  44.    
  45.  
  46. //    if(boxes[i]!=null && boxes[i+1]!=null &&
  47. //      //(boxes[i].getVolume() > Box[i+1].getVolume()))
  48. //    {
  49. //     Box temp = boxes[i];
  50. //     boxes[i] = boxes[i+1];
  51. //     boxes[i+1] = temp;
  52. //     hasSwapped = true;
  53. //    }
  54. //   }
  55. //  }
  56. // }
  57. //
  58. // public void print()
  59. // {
  60. //  for(int i = 0; i<boxes.length; i++)
  61. //  {
  62. //   if(boxes[i]!=null)
  63. //   {
  64. //   System.out.println(boxes[i]);
  65. //   }
  66. //  }
  67. // }
  68. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement