Hi!
I'm very new to javascript and i'm trying to write a script that allows me to:
-add to and substract from a value called temperature through methods warmer and cooler
-read temperature
-set a maximum and minimum value for temperature
this is what i've come up with:
Code:
public class Heater
{
private int temperature;
private int min;
private int max;
private int increment;
private int recMin;
private int recMax;
public Heater()
{
temperature = 15;
min = recMin;
max = recMax;
increment = 5;
}
public void insrtMin(int minimum)
{
recMin = minimum;
}
public void insrtMax(int maximum)
{
recMax = maximum;
}
public void warmer()
{
if ((temperature + increment) > max)
{
}
else
{
temperature = temperature + increment;
}
}
public void cooler()
{
if ((temperature - increment) < min)
{
}
else
{
temperature = temperature - increment;
}
}
public int returnTemp()
{
return temperature;
}
}
The code worked fine until I added the conditions to 'warmer' and 'cooler'. Now, however, only the cooler method seems to work. What did I miss?
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.