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

Java program Methods and Parallel Arrays Creating an output table of temperature

ID: 3770209 • Letter: J

Question

Java program

Methods and Parallel Arrays
Creating an output table of temperature for a zip-code
Write down the algorithm for the following:
       The program should hardcode the month names in an array.
       The program must accept the zip-code from the user.
       The program must accept the monthly average high, and the annual average lows for that zip-code from the user.
      The program must calculate the temperature range for each month: what is the temperature difference between high and low?
      The program must determine the annual average high, and the annual average low, and annual average temperature range.
The program Temperature.java must determine in what months there was the highest and lowest high and in what months was the highest and lowest low and in what months was the highest and lowest range.
Calculate of the average, highest, and lowest must each be a separate method.
Average, Highest, and Lowest methods each take one array as the input
(Average returns an average , Highest &Lowest return the position of the Highest or lowest)

Explanation / Answer

import java.util.Scanner;

public class Temperature {

public static void main (String[] args){

String months[] = new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
double temp[] = new double[12];
double average = 0;
double max, min;
String maxMonth = months[0];
String minMonth = months[0];
for (int i = 0; i < months.length; i++){

System.out.println ("Introduce the temperature for the month of " + months[i] + ":");
Scanner input = new Scanner(System.in);
double thismonth = input.nextDouble();
temp[i] = thismonth;

}

max = temp[0];
min = temp[0];

for (int x = 0; x < temp.length; x++){

if (temp[x] > max){

max = temp[x];
maxMonth = months[x];

}

if (temp[x] < min){

min = temp[x];
minMonth = months[x];

}

average += temp[x];

}

average = average / months.length;

System.out.println (maxMonth + " has been the warmest month of the year with an average temperature of " + max);
System.out.println (minMonth + " has been the coldest month of the year with an average temperature of " + min);
System.out.println ("The annual average temperature has been " + average);

}

}

thank you

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