Ask Question
2 October, 08:17

Suppose a meteorology station records the temperature and humidity at each hour of every day and stores the data for the past ten days including four numbers that indicate the day, hour, temperature, and humidity. Write a Java program that calculates the average daily temperature and humidity for the 10 days. The first index of data represents 10 days, the second index represents 24 hours, and the third index represents temperature and humidity, respectively. You may randomly select the values of temperature/humidity.

+5
Answers (1)
  1. 2 October, 10:02
    0
    The complete program is given below with step by step comments for explanation.

    Explanation:

    So we need to write a program that can calculate the average daily temperature and humidity. We can create a class named Weather_Station to do the job.

    public class Weather_Station

    {

    public static void main (String[] args)

    {

    / / we are told that the data is for 10 days and 24 hours so they are fixed and cannot be changed

    final int Days = 10;

    final int Hours = 24;

    / / Then we define a three-dimensional array named station for storing days, hours and temperature/humidity

    double[][][] station = new double[Days][Hours][2];

    / / Then we read input from a file

    Scanner input = new Scanner (System. in);

    / / Since there is a lot of data, using a loop to extract the data would be a good idea so we run a loop for 10*24 times to get the day, hour, temperature and humidity values.

    for (int k = 0; k < Days*Hours; k++)

    {

    int day = input. nextInt ();

    int hour = input. nextInt ();

    double temp = input. nextDouble ();

    double humidity = input. nextDouble ();

    station[day - 1][hour - 1][0] = temp;

    station[day - 1][hour - 1][1] = humidity;

    }

    / / Since we want to get the average temperature and humidity of each day for 10 days so we run a loop for days times (thats 10)

    for (int i = 0; i < Days; i++)

    {

    double Total_temp = 0;

    double Total_humidity = 0;

    / / Then we run another loop to add up all the temperatures and humidity values for each hour in a day and store them in Total_temp and Total_humidity respectively.

    for (int j = 0; j < Hours; j++)

    {

    Total_temp + = station[i][j][0];

    Total_humidity + = station[i][j][1];

    }

    }

    / / The average is simply the total number of temperature values divided by the number of hours, same goes for humidity.

    double Avg_temp=Total_temp / Hours;

    double Avg_humidity=Total_humidity / Hours;

    / / Then we print the values of any day's average temperature and humidity

    System. out. println ("For the Day of " + i + "Average Temperature is " + Avg_temp);

    System. out. println ("For the Day of " + i + "Average Humidity is " + Avg_humidity);

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Suppose a meteorology station records the temperature and humidity at each hour of every day and stores the data for the past ten days ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers