I'm not really sure how to validate the info of an object's arguments(parameters? if someone can also explain the difference, that would be great!). So basically, the default values of the variables need to be 1.0 but when I run anything below 1.0, it doesn't take into consideration the if statements that I have put up. For example, the negative values stay negative.How can I make it so that if anything is below 1.0, it must be set to 1.0? Thank you!
private double length;
private double width;
private double height;
public Box(double l, double w, double h){
length=l;
if(l<1.0)
l=1.0;
width=w;
if(w<1.0)
w=1.0;
height=h;
if(h<1.0)
h=1.0;
}
public void setLength(double l){
if(l<1.0)
l=1.0;
}
public void setWidth(double w){
if(w<1.0)
w=1.0;
}
public void setHeight(double h){
if(h<1.0)
h=1.0;
}
Here is the main
Box box3= new Box(7,8,9);
Box box4= new Box(-1.0,-2.0,-3.0);