THINK FIRST·CODE LATER

← All labs

Utility class and object counter

Problem

Write a class Temperature with:

  • a private field celsius;
  • a static counter of how many Temperature objects were created, readable with public static int getCount();
  • a method toFahrenheit() returning celsius * 9 / 5 + 32;
  • a static method fahrenheitToCelsius(double f) returning (f - 32) * 5 / 9.

TemperatureApp reads two numbers: a value in Celsius and a value in Fahrenheit. It creates two Temperature objects (with the Celsius value and with the converted Fahrenheit value) and prints:

In Fahrenheit: 77.00
In Celsius: 37.00
Objects created: 2

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.