Question: a) While designing a climate control system, you decide to create a ClimateControl class. Define this class according to the following specifications: (8 marks) There
a) While designing a climate control system, you decide to create a ClimateControl class. Define this class according to the following specifications: (8 marks)
There should be three attributes: a string attribute to store the mode, an integer attribute to store the temperature, and an integer attribute to store the timer. The initialiser method should take the temperature and the timer, while initially setting the mode to "cooling".
There should be an accessor method to read the temperature.
There should be a mutator method to toggle the mode. The method should check the current value. If it is "off", it will change it to "cooling". If it is "cooling" it will change it to "heating". Otherwise, it will change it to "off".
b) In part (a), the mode attribute was not made directly accessible outside the class. What is this feature called and why is it useful? (2 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
