/*
   This file defines Box5 objects.

   A Box5 object holds the information that would describe
   a box for the purposes of a shipping company.

   The data in a Box5 object is private, so the data can only
   be manipulated through methods that belong to the object
   (that is, through the "public interface" defined by this class).

   A Box5 object knows how to compute its volume and it knows
   how to return a printable description of itself.

   A Box5 object knows to label its largest dimension as its length.
   This is standard United States Postal Service practice. See
       http://pe.usps.com/text/qsg300/Q401.htm

   A Box5 object knows how to compute its "length plus girth".

   A Box5 object validates its data and throws an IllegalArgument
   exception if the box data violates a postal regulation.
*/

class Box5
{
   // Five (private) instance variables.
   private double length;
   private double height;
   private double width;
   private double weight;
   private int idNumber;

   // Define a Box5 constructor.
   public Box5(double dim1, double dim2, double dim3, double weight, int idNumber)
   {
      if ( dim1 < 0 || dim2 < 0 || dim3 < 0 )
         throw new IllegalArgumentException("negative dimension");

      if ( weight < 0 || weight > 70 )
         throw new IllegalArgumentException("illegal weight");

      this.length = dim1;
      this.height = dim3;
      this.width  = dim2;

      // this.length should be the largest
      // dimension of the box
      if (this.width > this.length)
      {
         // if width is larger than length
         // then swap the two values
         double temp = this.length;
         this.length = this.width;
         this.width = temp;
      }
      if (this.height > this.length)
      {
         // if height is larger than length
         // then swap the two values
         double temp = this.length;
         this.length = this.height;
         this.height = temp;
      }

      if ( this.lengthPlusGirth() > 108 )
         throw new IllegalArgumentException("illegal lenght plus girth");

      this.weight = weight;
      this.idNumber = idNumber;

   }//Box5 constructor


   // Since the data is private, we need to define
   // three "get methods" for the box dimensions.
   // These fields should not have "set methods" since
   // a real box cannot change its dimensions once it
   // has been constructed.
   public double getLength()
   {
      return this.length;
   }

   public double getHeight()
   {
      return this.height;
   }

   public double getWidth()
   {
      return this.width;
   }


   // The id number should only have a get method.
   public int getIdNumber()
   {
      return this.idNumber;
   }


   // For the weight, we should have both a get and a set method.
   public double getWeight()
   {
      return this.weight;
   }

   public void setWeight(int weight)
   {
      if ( weight < 0 || weight > 70 )
         throw new IllegalArgumentException("illegal weight");

      this.weight = weight;
   }


   // Define a method for computing the volume of the box.
   public double volume()
   {
      return height*width*length;
   }


   // Define a method to compute the "length plus girth" of the box.
   public double lengthPlusGirth()
   {
       return length+2*width+2*height;
   }


   // Override the toString() method from the Object class.
   public String toString()
   {
      return "Box5 object with "
             + "idNumber = " + this.idNumber + ", "
             + "length = " + this.length + ", "
             + "height = " + this.height + ", "
             + "width = "  + this.width + ", "
             + "and weight = " + this.weight + ".";
   }//toString()

}//Box5