In Java, Why am I getting this error:
Error: The constructor WeightIn() is undefined
Java Code:
public class WeightIn{
pr
The compiler is encountering a call to a "WeightIn()" no argument constructor, on this line:
WeightIn weight1 = new WeightIn(); //Error happens here.
The compiler is looking for a matching constructor in the class definition, and its not finding it. That's the error. (You do have a constructor defined: "WeightIn(double,double)" but that takes two arguments, and is not match.)
Several ways to fix this.
The easiest is to change the code in your main method to pass two arguments.
WeightIn weight1 = new WeightIn( 3.65, 1.7);
//weight1.setWeight(3.65);
//weight2.setHeight(1.7);
The calls to the setWeight and setHeight methods are redundant, since the members are already assigned values by the constructor method.