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

John has a weather station in his house. He has been keeping track of the fastes

ID: 3873332 • Letter: J

Question

John has a weather station in his house. He has been keeping track of the fastest wind speed for each day for two weeks. He would like to know the average wind speed over two weeks, the days on which the highest wind speed and the lowest wind speed were recorded, and the difference between the highest wind speed recorded and each day’s average wind speed.

Doing the following:

Modify the random function to return values in the range of 0 to 30 (representing wind speeds) use the random functions. Use this function to populate your array and then calculate the requirements of Mr. John.

Explanation / Answer

Program:

public class john{
   public static void main(String args[]){
       int[] a = new int[14]; //array to store wind sppeds
       int sum = 0,average=0;   //declaring variables to store sum and average
       int max = -1, min =31;   //as range is 0 to 30 considering max as -1 and min as 31
       int max_pos=0,min_pos=0; //assuming first day has min and max values
       for(int i=0;i<14;i++){   //loop to run for 2 weeks i.e., 14 days
           a[i] = (int)(Math.random() * 30);   //random function to generate random values
           sum += a[i];   //adding a[i] to sum
           //System.out.print(a[i]+" ");
           if(max<a[i]){ //if max value is less than a[i]
               max = a[i]; //updating max value
               max_pos = i+1; //updating max position
           }
           if(min>a[i]){   //if min is greater than a[i]
               min = a[i]; //updating min value
               min_pos = i+1; //updating min position
           }
       }
       average = sum/14; //average is sum by number of values
       System.out.println(average); //priniting values
       System.out.println("Highest speed was recorded on: "+max_pos+" day");
       System.out.println("Lowest speed was recorded on: "+min_pos+" day");
       System.out.println("Difference b/w Highest speed and average is: "+(max-average));
   }
}

Output:

13
Highest speed was recorded on: 5
Lowest speed was recorded on: 7
Difference b/w Highest speed and average is: 15


...........................

another output:

19
Highest speed was recorded on: 3 day
Lowest speed was recorded on: 2 day
Difference b/w Highest speed and average is: 10

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