Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-12-2012, 03:55 PM   PM User | #1
clue<
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
clue< is an unknown quantity at this point
conditions error

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?

thanks!
clue< is offline   Reply With Quote
Old 11-12-2012, 03:59 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
you need the "Java" forum not javascript
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 11-12-2012, 04:01 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 11-12-2012, 04:34 PM   PM User | #4
clue<
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
clue< is an unknown quantity at this point
Thanks! Sorry about that..
clue< is offline   Reply With Quote
Old 11-12-2012, 04:56 PM   PM User | #5
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,354
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title></title>
</head>

<body>
 <input name="" id="tst" /> <br />
 <input type="button" name="" value="Warmer" onmouseup="heater.heat('tst',1);"/>
 <input type="button" name="" value="Colder" onmouseup="heater.heat('tst',-1);"/>
 <input type="button" name="" value="Set Min" onmouseup="heater.setmin('tst',0);"/>
 <input type="button" name="" value="Set Max" onmouseup="heater.setmax('tst',300);"/>

<script  type="text/javascript">
/*<![CDATA[*/

var heater={

 init:function(o){
  heater[o.id]={
   obj:document.getElementById(o.id),
   temp:o.temperature,
   min:o.min,
   max:o.max,
   i:o.increment
  }
 },

 heat:function(id,ud){
  var o=heater[id],ud=typeof(ud)=='number'&&ud==0?0:ud<0?-1:1;
  if (o){
   o.obj.value=Math.min(Math.max(o.temp+=(ud*o.i),o.min),o.max);
  }
 },

 setmin:function(id,nu){
  var o=heater[id];
  if (o&&typeof(nu)=='number'){
   o.min=Math.min(nu,o.max);
   this.heat(id,0);
  }
 },

 setmax:function(id,nu){
  var o=heater[id];
  if (o&&typeof(nu)=='number'){
   o.max=Math.max(nu,o.min);
   this.heat(id,0);
  }
 }

}

heater.init({
 id:'tst',
 temperature:100,
 min:10,
 max:200,
 increment:2
});

/*]]>*/
</script>

</body>

</html>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:00 PM.


Advertisement
Log in to turn off these ads.