Question

Consider an object oriented program for a temperature controller. What objects could use to do this?...

Consider an object oriented program for a temperature controller. What objects could use to do this? What methods and attributes would these objects have?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

temperature controller should be an interface that has two methods one is to increaseTemperature and another is to decrease temperature. any class that needs temperature controle will then implement this interface.

public class TempCntrl implements TempCntrler{
   double temperature;
   public double getTemperature() {
       return temperature;
   }

   public void setTemperature(double temperature) {
       this.temperature = temperature;
   }

   public void increaseTemperature(int increaseBy){
       temperature = temperature + increaseBy;
   }
  
   public void decreaseTemperature(int decreaseBy){
       temperature = temperature - decreaseBy;
   }

   @Override
   public String toString() {
       return "TempCntrl [temperature=" + temperature + "]";
   }
  
  
}

interface TempCntrler{
   public void increaseTemperature(int increaseBy);
   public void decreaseTemperature(int decreaseBy);
}

class AC extends TempCntrl{
     
}

class Oven extends TempCntrl{
     
}

Add a comment
Know the answer?
Add Answer to:
Consider an object oriented program for a temperature controller. What objects could use to do this?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT