Loading...
Loading...
Loading...
A weather app gets readings in either Celsius or Fahrenheit but always stores Celsius, and shows both. F = C × 9 / 5 + 32.
Write a class Temperature with one field celsius, a method double fahrenheit() and a method void setFahrenheit(double f) that converts and stores the value in celsius. Use one object per reading.
C value or F value.c C = f F, both with one digit after the decimal point.Example
Input
3 C 37 F 212 C -40
Output
37.0 C = 98.6 F 100.0 C = 212.0 F -40.0 C = -40.0 F
37 °C is 98.6 °F, 212 °F is boiling water, and -40 is the same in both scales.
Try the problem first. Open one hint at a time.
For C, set the field directly; for F, call setFahrenheit.
The reverse formula is C = (F - 32) × 5 / 9.
Only celsius is stored, so fahrenheit() always works it out from the field.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor