Home Segments Index Top Previous Next

191: Practice

Write a method for Integer instances named celsiusToFahrenheit that, when sent to a number representing temperature in Celsius answers twice that number plus 30.

Next, amend your celsiusToFahrenheit method such that it displays “Performing an approximate temperature conversion” every time that it is entered.

Next, improve your celsiusToFahrenheit method by having it add 40 to the argument, multiply by 9/5, and subtract 40. Be sure that your method answers with an integer.

Finally, change your celsiusToFahrenheit method such that the receiver is in Celsius degrees relative to absolute zero and the result answered is in Fahrenheit degrees relative to absolute zero. Absolute zero is -273 degrees Celsius.

For each change, comment on the corresponding benefit provided by procedure abstraction.