title: I am getting the error "actual and formal argument lists differ in length" even though I have a constructor with 3 double parameters
body: <p>Question: I am getting the error below even though I have a constructor in Box.java with three parameters.</p>
  
  <pre><code>BoxTest.java:19: error: constructor Box in class Box cannot be applied to given types;
          Box box1 = new Box(length, width, height);
                     ^
    required: no arguments
    found: double,double,double
    reason: actual and formal argument lists differ in length
  </code></pre>
  
  <p>Assignment: Create a Box class with the following:</p>
  
  <ul>
  <li>instance variables length, width, and height</li>
  <li>a no-argument Box constructor — use 1.0 as the default value for width, length and height.</li>
  <li>a Box constructor with three parameters.  There can be NO zero or negative value for the instance variables.  Use 1.0 as the default value for width, length or height if a parameter is invalid. </li>
  <li>get and set (accessor and mutator) methods for each instance variable.  There can be NO zero or negative values for the instance variables so be sure to validate the parameter in the set methods.  Do NOT update the instance variable if the parameter is invalid (zero or negative).  Do NOT use exception handling.</li>
  <li>a toString method that returns a String with the length, width and height, clearly labeled.  Format each value to two places past the decimal point.</li>
  <li>a calculateArea method that calculates and returns the surface area of the box (all 6 sides)</li>
  <li>a calculateVolume method that calculates and returns the volume of the box</li>
  </ul>
  
  <p>Create a BoxTest program with the following. </p>
  
  <ul>
  <li>an array named boxes that has size (length) 4</li>
  <li>4 Box objects - place each Box in the array. One Box object must be created with user input for the length, width and height. One Box object must be created with the no-argument constructor. The other Boxes should be created with literal values (2, 3.5, 5.75, etc.).</li>
  <li>use an enhanced for loop to display the length, width, height, area and volume of each Box object, clearly labeled. Do this by calling the appropriate methods. Call the toString method for the length, width and height. Format the area and volume to two places past the decimal point.</li>
  </ul>
  
  <p>BoxTest.java</p>
  
  <hr>
  
  <pre><code>import java.util.Scanner;
  
  public class BoxTest
  {
      public static void main(String[] args)
      {
          Scanner input = new Scanner(System.in);
          System.out.print("Enter length: ");
          double length = input.nextDouble();
  
          System.out.print("Enter width: ");
          double width = input.nextDouble();
  
          System.out.print("Enter heigth: ");
          double height = input.nextDouble();
  
          Box[] boxes = new Box[4];
  
          Box box1 = new Box(length, width, height);
          boxes[0] = box1;
  
          Box box2 = new Box();
          boxes[1] = box2;
  
          Box box3 = new Box(2.0, 3.5, 5.75);
          boxes[2] = box3;
  
          Box box4 = new Box(9.0, 12.0, 15.0);
          boxes[3] = box4;
  
          System.out.println(displayBox(box1));
      }
  
      private static String displayBox(Box box)
      {
          System.out.print(box.toString());
      }
  }
  </code></pre>
  
  <p>Box.java</p>
  
  <pre><code>public class Box
  {
      // Instance variables
      private double length;
      private double width;
      private double height;
  
      // ********************* DEFAULT CONSTRUCTOR *******
      public Box()
      {
          this(1.0, 1.0, 1.0);
      }
  
      // ********************* CONSTRUCTOR *******
      public Box(double length, double width, double height)
      {
          if(length &gt; 0)
          {
              this.length = length;
          }
          else
          {
              this.length = 1.0;
          }
  
  
          if(width &gt; 0)
          {
              this.width = width;
          }
          else
          {
              this.width = 1.0;
          }
  
  
          if(height &gt; 0)
          {
              this.height = height;
          }
          else
          {
              this.height = 1.0;
          }
      }
  
      public double getLength()
      {
          return length;
      }
  
      public double getWidth()
      {
          return width;
      }
  
      public double getHeight()
      {
          return height;
      }
  
      public void setLength(double length)
      {
          if(length &gt; 0)
          {
              this.length = length;
          }
      }
  
      public void setWidth(double width)
      {
          if(width &gt; 0)
          {
              this.width = width;
          }
      }
  
      public void setHeight(double height)
      {
          if(height &gt; 0)
          {
              this.height = height;
          }
      }
  
      public String toString()
      {
          return String.format("%s = %.2f%n%s = %.2f%n%s = %.2f%n", "Length", length, "Width", width, "Height", height);
      }
  
      public double calculateArea(double length, double width, double height)
      {
          double area = 2 * (length * width) + 2 * (height * width) + 2 * (length * height);
          return area;
      }
  
      public double calculateVolume(double length, double width, double height)
      {
          double volume = length * width * height;
          return volume;
      }
  }
  </code></pre>
  
  <p>Error:</p>
  
  <hr>
  
  <pre><code>BoxTest.java:19: error: constructor Box in class Box cannot be applied to given types;
          Box box1 = new Box(length, width, height);
                     ^
    required: no arguments
    found: double,double,double
    reason: actual and formal argument lists differ in length
  
  BoxTest.java:25: error: constructor Box in class Box cannot be applied to given types;
          Box box3 = new Box(2.0, 3.5, 5.75);
                     ^
    required: no arguments
    found: double,double,double
    reason: actual and formal argument lists differ in length
  
  BoxTest.java:28: error: constructor Box in class Box cannot be applied to given types;
          Box box4 = new Box(9.0, 12.0, 15.0);
                     ^
    required: no arguments
    found: double,double,double
    reason: actual and formal argument lists differ in length
                                           ^
  3 errors
  </code></pre>