title: How to correctly invoke toString
body: <p>I'm trying to create a <code>toString</code> method in a Box class to call in a BoxTest class. I've set up the methods I want to call (<code>getLength</code>, <code>getHeight</code>, <code>getWidth</code>, <code>calculateArea</code>, <code>calculateVolume</code>), which work fine by themselves, but I'm unsure how to use them when calling <code>toString</code>.</p>
  
  <p>Here is a pastebin (<a href="http://pastebin.com/Ex520ST6" rel="nofollow">http://pastebin.com/Ex520ST6</a>) of my current code.</p>
  
  <h3>Box</h3>
  
  <pre><code>public class Box
  {
      private double length = 1.0;
      private double width = 1.0;
      private double height = 1.0;
  
      public Box(double length, double width, double height) // constructor with thrown exceptions
      {
          if (length &lt;= 0)
              throw new IllegalArgumentException("Values must be higher than 0");
  
          if (width &lt;= 0)
              throw new IllegalArgumentException("Values must be higher than 0");
  
          if (height &lt;= 0)
              throw new IllegalArgumentException("Values must be higher than 0");
  
          this.length = length;
          this.width = width;
          this.height = height;
      }
  
      public void setLength(double length)
      {
          if (length &lt;= 0)
              throw new IllegalArgumentException("Values must be higher than 0");
  
          this.length = length;
          System.out.println("The new length is: " + length);
  
      }
      public double getLength()
      {
          System.out.println("The length is: " + length);
          return length;
      }
      public void setWidth(double width)
      {
          if (width &lt;= 0)
              throw new IllegalArgumentException("Values must be higher than 0");
  
          this.width = width;
          System.out.println("The new width is: " + width);
      }
      public double getWidth()
      {
          System.out.println("The width is: " + width);
          return width;
      }
      public void setHeight(double height)
      {
          if (height &lt;= 0)
              throw new IllegalArgumentException("Values must be higher than 0");
  
          this.height = height;
          System.out.println("The new height is: " + height);
      }
      public double getHeight()
      {
          System.out.println("The height is: " + height);
          return height;
      }
      public double calculateArea()
      {
          double area = (double) (2*length*width + 2*length*height + 2*width*height);
          System.out.println("The area is: " + area);
          return area;
      }
      public double calculateVolume()
      {
          double volume = (double) length*width*height;
          System.out.println("The volume is: " + volume);
          return volume;
      }
      public String toString()
      {
          return String.format("The length is %f, the width is %f, the height is %f, the area is %f, the volume is %f,");
      }
  }
  </code></pre>
  
  <h3>BoxTest</h3>
  
  <pre><code>public class BoxTest
  {
      public static void main (String[] args)
      {
          Box[] boxes = new Box[4];
  
          boxes[0] = new Box(1.0,2.0,3.0);
          boxes[1] = new Box(4.0,5.0,6.0);
          boxes[2] = new Box(1.0,7.0,8.0);
          boxes[3] = new Box(1.0,9.0,9.0);
  
          for (Box theBoxes : boxes)
          {
  
              System.out.printf(theBoxes.getLength(),theBoxes.getWidth(),theBoxes.getHeight(),theBoxes.calculateArea(),theBoxes.calculateVolume().toString());
  
          }
  
          boxes[3].setLength(11.0); // debug
      }
  }
  </code></pre>
  
  <ol>
  <li>Am I on the right track, generally</li>
  <li>Should I be using <code>"%s"</code> specifier in the <code>toString</code> heading</li>
  <li>Do I still need a format specifier in the <code>printf</code>, and if so, should it be <code>%s</code> or <code>%f</code>, as my methods are type <code>double</code>.</li>
  </ol>
  
  <p>Thank you!</p>