Question
In java!!!!! Suppose a meterology station records the temperature and humidity every hour of every day and stores the data for the past ten days
In java!!!!!
Suppose a meterology station records the temperature and humidity every hour of every day and stores the data for the past ten days in a text file named weather.txt (copy from shared directory).
Each line of the file consists of four numbers that indicate the day, hour, temperature, and humidity. The contents of the file could look like:
1 1 76.4 0.92 1 2 77.7 0.93 . . . 10 23 97.7 0.71 10 24 98.7 0.74
Note that the lines in the file are not necessarily in increasing order of day or hour. For example, the file could appear as shown below:
5 23 77.7 0.93 9 8 77.7 0.93 . . . 5 18 77.7 0.93 2 23 77.7 0.93
Your task is to write a program that calculates the average daily temperature and humidity for the ten days. Open and read the file into a three-dimensional array named data. The first index of data ranges from 0 to 9 and represents 10 days; the second index ranges from 0 to 23 and represents 24 hours; and the third index ranges from 0 to 1 and represents temperature and humidity, as depicted below.
data [ day ] [ hour ] [ temperature|humidity]
Note the days are numbered from 1 to 10 and the hours from 1 to 24 in the file. Because the array index starts from 0, data [0][0][0] stores the temperature for day 1 at hour 1 and data [9][23][1] stores the humidity for day 10 at hour 24.
Hints:
Create a three-dimensional array for storing temperature and humidity.
Write a loop to read data into the array.
Write a loop to add all temperatures for each hour in a day and all humidity for each hour.
Display the average daily temperature and humidity.
Sample output
Day Avg Temp Avg Hum 0 77.770800 0.929583 1 77.312500 0.929583 . . . 9 79.354200 0.912500
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started