Advertisement
scaawt

Box

Oct 24th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. /**
  2.  * written by tariq scott
  3.  */
  4. public class Box {
  5.  
  6.   private String label;
  7.   private double length;
  8.   private double width;
  9.   private double height;
  10.  
  11.   //constructors
  12.   public Box () // my default constructor
  13.   {
  14.     this.label = "none yet";
  15.     this.length = 1.0;  
  16.     this.width = 1.0;
  17.     this.height = 1.0;
  18.   }
  19.   public Box (String aLabel, double aLength, double aWidth, double aHeight)
  20.   {
  21.     //TODO fill in mutators
  22.   }
  23.   //accessors
  24.   public String getLabel ()
  25.   {
  26.     return this.label;
  27.   }
  28.   public double getLength ()
  29.   {
  30.     return this.length;
  31.   }
  32.   public double getWidth ()
  33.   {
  34.     return this.width;
  35.   }
  36.   public double getHeight ()
  37.   {
  38.     return this.height;
  39.   }
  40.   public void setLabel (String aLabel)
  41.     {
  42.       this.label = aLabel;
  43.     }
  44.   public void setLengh (double aLength)
  45.   {
  46.     if (aLength >= 0.0)
  47.     {
  48.       this.length = aLength;
  49.     }
  50.   }
  51.   public void setWidth (double aWidth)
  52.   {
  53.     if (aWidth >= 0.0)
  54.     {
  55.       this.width = aWidth;
  56.     }
  57.   }
  58.   public void setHeight (double aHeight)
  59.   {
  60.     if (aHeight >= 0.0)
  61.     {
  62.       this.height = aHeight;
  63.     }
  64.   }
  65.   //other methods
  66.   public String toString()
  67.   {
  68.     return this.label + " " + this.width + " " + this.length + " " + this.height;
  69.   }
  70.   public boolean equals (Box aBox)
  71.   {
  72.     return aBox != null &&
  73.     this.label.equals(aBox.getLabel()) &&
  74.     this.width == aBox.getWidth() &&
  75.     this.height == aBox.getHeight ();
  76.   }
  77.   //volume method
  78.   public double getVolume;
  79.   {
  80.     return this.getWidth()*this.getLength()*this.getHeight();
  81.   }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement