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());

}

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

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>);
This article has been dead for over six months. Start a new discussion instead.