Question: Java programming 5th edition chapter 9 two dimensional Arrays Write a program that uses a two-dimensional array to store the highest and lowest temperatures for

Java programming 5th edition chapter 9 two dimensional Arrays

Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and highest and lowest temperature of the year. Your program must consist of the following methods:

getData():This method reads the data from a file (see values below) and stores it in the 2D array

printMatrix(): This method prints the data in matrix format (as the input data is formatted below without the borders)

averageHigh(): This method calculates and returns the average high temperatures of the year

averageLow(): This method calculates and returns the average low temperature of the year

indexHighTemp(): This method returns the index of the highest temperatures in the array

indexLowTemp(): This method returns the index of the lowest temperatures in the array

Except for printing the matrix, display all output in main(). Display the high and low values found with the indices from the indexHighTemp() and indexLowTemp() methods.

The lines are just to keep things separate so you can see them

High____Low

Temps__Temps

50 _______16 47_______ -2 65_______ 35 68_______ 41 73 _______50 81_______ 66 93 _______73 101_______82 90 _______75 75 _______60 67_______ 53 56________ 38

Here is what I have so far

import java.util.*; import java.io.*;

public class Temperature { public static void main(String[]args)throws FileNotFoundException { //Opening file to get temperatures Scanner fileReader = new Scanner(new File("infile.txt")); //Declare 2D Arrays int rows = 12; int col = 2; int[][] matrix = new int[rows][col];

//column headings System.out.println("High " + " Low"); System.out.println("Temps " + " Temps"); }//end main public static void getData(int[][] matrix, Scanner file) { for(int rows = 0; rows < matrix.length; rows++) for(int col = 0; col < matrix[rows].length; col++) matrix[rows][col] = file.nextInt(); }//end getData() public static void printMatrix(int[][] matrix) { }//end printMatrix public static double averageHigh() { }//end averageHigh public static double averageLow() { }//end averageLow public static void indexHighTemp() { }//end indexHighTemp public static void indexLowTemp() { }//end indexLowTemp

}//end class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!