vendredi 24 juillet 2015

I want modify a method in java so that the value of temperature does not exceed the value of max

Hi I'd like to modify the method warmer so that temperature does not exceed the variable max, i'm guessing I can use some sort of if statement but how do I implement it, basic question, but i'm a beginner trying to self learn java. Any help would be welcome, thanks.

public class Heater
{
//the current temperature
private double temperature;
private double min;
private double max;
private double increment;

/**
 * Create a Heater object, with initial temperature
 * of 15 degrees using constructor.
 */
public Heater(double min, double max)
{
    temperature = 15.0;
    this.min = min;
    this.max = max;
    increment = 5.0;
}

/**
 * Increase temperature by 5 degrees using mutator method
 */
public void warmer()
{
    temperature += increment;
    //Modify warmer method so that it will not allow temperature to be set to a value greater than max.
    if( temperature > max)
    {

    }
}

 /**
 * Decrease temperature by 5 degrees using mutator method
 */
public void cooler()
{
    temperature -= increment;
}

}

Aucun commentaire:

Enregistrer un commentaire