Please write in JAVA ONLY Write a program that uses a twodim

Please write in JAVA ONLY!

Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year.

Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year.

Your program should output all the values in the array and then output the average high and the average low.

Solution

Temparatre.java

import java.util.Scanner;


public class Temparatre {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       int temp[][] = new int[12][2];
       for(int i=0; i<temp.length; i++){
           System.out.print(\"Enter high temparature for the month \"+(i+1)+\": \");
           temp[i][0] = scan.nextInt();
           System.out.print(\"Enter low temparature for the month \"+(i+1)+\": \");
           temp[i][1] = scan.nextInt();
       }
       System.out.println(\"Array values are : \");
       for(int i=0; i<temp.length; i++){
           System.out.println(temp[i][0]+\" \"+temp[i][1]);
       }
       double highTempAverage = getHighTempAverage(temp);
       System.out.println(\"The average of all high temparatures is \"+highTempAverage);
       double lowTempAverage = getLowTempAverage(temp);
       System.out.println(\"The average of all low temparatures is \"+lowTempAverage);
   }
   public static double getHighTempAverage(int h[][]){
       int sum = 0;
       for(int i=0; i<h.length; i++){
           sum = sum + h[i][0];
       }
       return sum/(double)h.length;
   }
   public static double getLowTempAverage(int h[][]){
       int sum = 0;
       for(int i=0; i<h.length; i++){
           sum = sum + h[i][1];
       }
       return sum/(double)h.length;
   }
}

Output:

Enter high temparature for the month 1: 20
Enter low temparature for the month 1: 10
Enter high temparature for the month 2: 30
Enter low temparature for the month 2: 20
Enter high temparature for the month 3: 40
Enter low temparature for the month 3: 30
Enter high temparature for the month 4: 50
Enter low temparature for the month 4: 40
Enter high temparature for the month 5: 60
Enter low temparature for the month 5: 50
Enter high temparature for the month 6: 70
Enter low temparature for the month 6: 60
Enter high temparature for the month 7: 80
Enter low temparature for the month 7: 70
Enter high temparature for the month 8: 90
Enter low temparature for the month 8: 80
Enter high temparature for the month 9: 30
Enter low temparature for the month 9: 10
Enter high temparature for the month 10: 40
Enter low temparature for the month 10: 20
Enter high temparature for the month 11: 50
Enter low temparature for the month 11: 30
Enter high temparature for the month 12: 60
Enter low temparature for the month 12: 40
Array values are :
20 10
30 20
40 30
50 40
60 50
70 60
80 70
90 80
30 10
40 20
50 30
60 40
The average of all high temparatures is 51.666666666666664
The average of all low temparatures is 38.333333333333336

Please write in JAVA ONLY! Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Write two
Please write in JAVA ONLY! Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Write two

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site