Back to Challenge Set 15

Code Challenge: Temperature Band

Difficulty  

divider

The Brief

What they asked for
The greenhouse controller needs to know what to do at a
given temperature. Too cold, fine, or too hot, and what
action to take. One reading in, one instruction out.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Return the instruction as a string; do not print it inside the method. The main program prints what comes back.
  • Three bands means two boundaries. The brief does not give them, so you choose both and write them in your requirements list.
  • Call it with a reading exactly on each boundary and check you get one answer — not two, and not none.
  • The method needs one parameter. Whether it is an int or a double is your decision too; say which, and why.

Where to Start

Only one-star challenges have this section. If you already know how to begin, skip it — and when you move up to two stars, working out the order yourself is part of the job.

  1. Decide your two boundary temperatures and write them down.
  2. Write a method with one parameter and a string return type.
  3. Use early returns, the way Activity 2.3's Status did: check one end of the range first and work across.
  4. Print the result of at least five calls: one in each band, and one on each boundary.

Sample Output

Sample Output
12 -> Turn heaters on
21 -> No action
34 -> Open vents

These three readings sit well inside each band, so any sensible boundaries give these lines. Test both of your boundaries exactly; each should give one answer.


Submit

Your requirements list and your program file, named cc-temperature-band.

Commence Challenge