The program is about computing the temperature of a warm object after it has been put in a freezer.The freezer temperature is constant at -20 degrees. Once the object is in the freezer, it's temperature drops by (K * dt) degrees in each second, where K=0.001 and dt is the difference between the current object temperature and the freezer temperature. The task requires me to method should compute the time in seconds it takes for the object to cool down from the given initial temperature until it has reached a temperature that is less or equal to the target temperature.
The result should be an int value. The method should return the value -1 if the target temperature is less or equal to the freezer temperature. In the solution, I have to use a loop that keeps track of the changing temperature of the object second-by-second. I don't know how to implement the timeToCool method. Here is what I have so far:
public static int timeToCool(double initialTemperature, double targetTemperature) {
return 0;
}
public static void timeToCoolTest(double initialTemperature, double targetTemperature) {
System.out.println("### Time To Cool");
System.out.println("Initial temperature = " + initialTemperature);
System.out.println("Target temperature = " + targetTemperature);
int timeTaken = timeToCool(initialTemperature, targetTemperature);
System.out.println("Time to cool = " + timeTaken + " seconds\n");
}
Any help is appreciated thank you :).