Create a class called Weather and include in it an instance variable named tempe
ID: 3629646 • Letter: C
Question
Create a class called Weather and include in it an instance variable named temperature that is an array of 5 integers. Then, Create a static method calcAverage that takes an integer array as input and returns the average temperature (double) of the array. The definition of a static method begins public static... . Next, Create a static method printArray that takes an integer array as input and prints all the values in it, and finally in a main method, ask the user to input 5 temperature values; store these in the integer array. Then invoke the printArray method and the calcAverage method. Also, print the average. The output should look like this,Welcome to the Average Temperature Program
Please enter 5 temperatures.
Enter temperature: 10
Enter temperature: 25
Enter temperature: 48
Enter temperature: 87
Enter temperature: 63
Average temperature: 46.6
Temperatures in the array: 10 25 48 87 63
Thank you for using this program, goodbye.
Explanation / Answer
import java.util.*; class Weather { public static double calcAverage(int[] a) { double sum=0; for(int i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.