lundi 27 février 2017

There is something wrong with the if-statement in our setter

We are making a setter with the if-statement. We are trying to limit the approved values, and are using a print-method to print out the value that is set, or "wrong" if the value is not accepted.

This is the method:

public Sykkel(String colour)
{
    // initialise instance variables
    super(1, colour);
    this.height = height;
}

public void setHeight (int height) {
    if(height > 35 && height < 70){
        System.out.println("Sykkelen er " + height + " cm høy.");
    } else {
        System.out.println("Wrong");
    }
}

public int getHeight() {
    return height;
}

No matter what we set as the height it prints out "Wrong". Does anyone see the error in the code?

we've tried both this.height and just height, but the outcome is still the same.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire