Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Weather Statistics Write a program that uses a structure to store the following

ID: 3685288 • Letter: W

Question

Weather Statistics
Write a program that uses a structure to store the following weather data for a particular month:
Total Rainfall
High Temperature
Low Temperature
Average Temperature


The program should have an array of 12 structures to hold weather data for an
entire year. When the program runs, it should ask the user to enter data for each
month. (The average temperature should be calculated.) Once the data are entered
for all the months, the program should calculate and display the average monthly
rainfall, the total rainfall for the year, the highest and lowest temperatures for the
year (and the months they occurred in), and the average of all the monthly average
temperatures.


**Only accept temperatures within the range between –100 and +140
degrees Fahrenheit.**

Explanation / Answer

import java.util.*;
class Weather
   {
       double rain, high_temp, low_temp, avg_temp;  
   }

class TestWeather
   {
       public static void main(String args[])
           {
               int tot_rain =0 ;
               double avg_rain =0 ;
               Weather w[] = new Weather[3];

               for(int i=0;i<3;i++)
                   {
                       Scanner s = new Scanner(System.in);
                       w[i] = new Weather();
                       System.out.println("Enter the Total Rainfall of month" + (i+1));
                       w[i].rain = s.nextDouble();

                       System.out.println("Enter the High Temperature of month" + (i+1));
                       w[i].high_temp = s.nextDouble();

                       System.out.println("Enter the Low Temperature of month" + (i+1));
                       w[i].low_temp = s.nextDouble();          

                       w[i].avg_temp = (w[i].high_temp + w[i].low_temp)/2;
                   }
              
               double min_temp, max_temp;
               min_temp = w[0].low_temp;
               max_temp = w[0].high_temp;
               for(int i=0;i<3;i++)
                   {
                       tot_rain += w[i].rain;
                       avg_rain = tot_rain/3;
                      
                       if(min_temp > w[i].low_temp)
                           min_temp = w[i].low_temp;
                       if(max_temp < w[i].high_temp)
                           max_temp = w[i].high_temp;
                   }
               System.out.println("TOTAL YEARLY RAINFALL : " + tot_rain + " TOTAL AVG RAIN : " + avg_rain + " MIN TEMPERATUR : " + min_temp + " MAX TEMPERATUR : " + max_temp);
           }
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote