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

This program will work; with arrays which.nr passed to methods \'the purpose is

ID: 3685181 • Letter: T

Question

This program will work; with arrays which.nr passed to methods 'the purpose is to collect ds about the high temperatures for a 5 day interval for each of 2 cites Some statistics will be computed for each city.md the temperatures for the 2 a ties will be compared The first step is to call a method which will get the high temperatures for 5 days in city A Thu method will prompt the user the numbers and read them into an array This array will be return to the mam method The second step is to call the same method and have it get the high temperatures for 5 days in B. This method will return the array to the main method, as before The next step is to pass the array for city A to a method which will calculate the average temperature and return it to the mam method Then, the program will call the averaging method again to have the average found for the array for city B The program will then call a method and pass the array for city A and the array for city B to it. The method will compare each of the corresponding temperature. and return the number of days whine city A was warmer than city B Hie program will then call a method and pass the array for city B and the array for city A to it. The method will compare each of the corresponding temperatures and rerun the number of days when city B was warmer than city A The main method \u. ass a string saying City A", the array for city A. the average for city A. and the number of times city A w as warmer to a method which will displav these values to the met The main method will pass a string saying City B. the array tor cm B the average for city B and the numbe o: tunes city B was warmer to the above mentioned method which will display these values to the user

Explanation / Answer

/**** TemperatureAndDay.java ***/

import java.util.Scanner;

public class TemperatureAndDay {

   public static double average(double[] list) {
   double[] result = new double[5];
   double sum = 0.0;
   for (int i = 0; i < list.length; i++) {
   sum = sum + list[i];
   }
   return sum/5;
}
  
   public static double[] read() {
  
   Scanner sc = new Scanner(System.in);
  
   double[] result = new double[5];

   for (int i = 0; i < 5; i++) {
   result[i] = sc.nextDouble();
   }
   return result;
}

   public static int greater(double[] list1, double[] list2) {
   int count = 0;
   for (int i = 0; i < 5; i++) {
   if(list1[i] > list2[i]) count++;
   }
   return count;
}

public static void main(String[] args) {

double [] temperature1 = new double [5];
double [] temperature2 = new double [5];

System.out.println("Enter temperature for city A: ");
temperature1 = read();
System.out.println("Enter temperature for city B: ");
temperature2 = read();

double average1 = average(temperature1);
double average2 = average(temperature2);

int count1 = greater(temperature1,temperature2);
int count2 = greater(temperature2,temperature1);

System.out.print("City A, ");
for (int i = 0; i < 5; i++) {
   System.out.print(temperature1[i]+" ");
   }

   System.out.print(", Average: "+ average1 + ", was warmer than City B on " + count1 + " days ");

   System.out.println("");

   System.out.print("City B, ");
for (int i = 0; i < 5; i++) {
   System.out.print(temperature2[i]+" ");
   }

   System.out.print(", Average: "+ average2 + ", was warmer than City A on " + count2 + " days ");


}
}

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