i an writing a room class java code that returns the temperature status of the room and return if a lightbulb is on or off.

how do i write the method for the temperature?

public class SittingRoom {

     String SRlightBulb;
    int   SRTemperature; 

    public SittingRoom()
    {String InitialStatus = null;int InitialTemp;
        SRlightBulb = InitialStatus;
        SRTemperature = InitialTemp;
    }


    void switchLightOn()
    {
        SRlightBulb = "ON";
    }
   void switchLightOff()
   {
       SRlightBulb = "OFF";
   }
  public  String checkSRLightBulbStatus()
   {
      return SRlightBulb; 
   }

     public int checkTemperature()
  {
      return SRTemperature;
  }

public static void main (String [] arg)
{
SittingRoom n = new SittingRoom();
System.out.println(n.checkTemperature());

}

}

get2tk,

Source program must be surrounded with BB code tags: See # icon at toolbar and also read How to use bb code tags?.

Firstly, get in the habit of making your instance variables private.

Secondly, not that it's going to make a whole lot of difference, but wouldn't it be easier to make SRlightBulb a boolean? True means on, False means off?

Thirdly, when you call the constructor of your class, which parameters are being passed? Using the default constructor (no arguments), the light bulb status is going to be null, but what will the temperature instance variable be set to?

If you're trying to modify the room temperature, I would do something like...

public void setTemp(int n)
{
SRTemperature = n;
}

and to access that method...

n.setTemp(<temp>);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.