after tweaking my code and moving on to the second section, I'm not sure why the output for part 2 is incorrect and it mostly outputs 0s and other numbers not in the array? I put an output for the array just to check what was going on but you can pretty much ignore it. Not sure where I'm going wrong any pointers? This time I also included my task:
//temperature management
import java.util.Scanner;
import java.util.Arrays;
public class temperaturemanagement
{
Scanner in = new Scanner(System.in);
//task 1
//To simulate the monitoring required, write a routine that allows entry of the apartment’s temperature in degrees Celsius. The routine checks whether the temperature is within the acceptable range, too high or too low and outputs a suitable message in each case.
public void task1()
{
System.out.println("Input Temperature: ");
double temperature = in.nextDouble();
double temperaturerounded = Math.round(temperature * 10) / 10.0;
if (temperaturerounded >=22 && temperaturerounded <=24)
{
System.out.println("Normal");
}
else if (temperaturerounded <22)
{
System.out.println("Too Low");
}
else if (temperaturerounded >24.0)
{
System.out.println("Too High");
}
}
//task 2
//Write another routine that stores, in an array, the temperatures taken over a period of five hours. This routine calculates the difference between the highest temperature and the lowest temperature. Then it outputs the highest temperature, the lowest temperature, and the difference between these temperatures.
public void task2()
{
System.out.print("Input Number of Hours: ");
int hour = in.nextInt();
//*12 because every 5 minutes and since there are 60 minutes in a hour
// this means 60/5 = 12 hence 12* the number of hours inputted
int loophours = hour*12 +1;
//loops array, rounds input and sorts the array by ascending order
//using Array.sort
double[] tempstorage = new double [loophours];
for (int i=1; i<loophours; i++)
{
System.out.println("Temp Count: " +i);
double temperature = in.nextDouble();
double temperaturerounded = Math.round(temperature * 10) / 10.0;
tempstorage[i] = temperaturerounded;
Arrays.sort(tempstorage);
}
//prints the positions 1 (lowest temperature) and loophours (highest temperature)
for (int i=1; i<loophours; i++)
{
System.out.println(tempstorage[i]);
}
double min = tempstorage[1];
System.out.println(min);
double max = tempstorage[loophours-1];
System.out.println(max);
double difftemp = max - min;
System.out.println("Highest Temperature: "+max);
System.out.println("Lowest Temperature: "+min);
System.out.println("Difference between Temperatures: "+difftemp);
}
}