Question

In: Computer Science

IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...

IN JAVA

Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   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.

im trying to figure out how to get a 2D array to store a number for the highest and the lowest of each month. I can get it to do either the highest or lowest but not both.

Thanks

Solutions

Expert Solution

import java.util.Scanner;
class ArrayAssignmentClient {

public static void main(String[]args){


int i,j;
double [][] arr = new double[12][2];
Scanner scan = new Scanner(System.in);

System.out.print("Enter lowest and highest temparatures of 12 months : ");
for(i=0; i<12; i++)
{
for(j=0; j<2; j++)
{
arr[i][j] = scan.nextDouble();
}
}


System.out.print("The lowest and highest temparatures of 12months are :\n");
for(i=0; i<12; i++)
{
for(j=0; j<2; j++)
{
System.out.print(arr[i][j]+ " ");
}
System.out.println();
}
System.out.println(averageHigh(arr));
System.out.println(averageLow(arr));


}


public static double averageHigh(double[][]arr){
double total = 0;
double average = 0;
for (int i = 0; i <12; i++) {
total += arr[i][1];
average = total /12;
}
return average;
}

public static double averageLow(double[][]arr){
double total = 0;
double average = 0;
for (int i = 0; i <12; i++) {

total += arr[i][0];
average = total / 12;
}
return average;

}
}


Related Solutions

Using JAVA Write a program that uses a 2-D array to store the highest and lowest...
Using JAVA Write a program that uses a 2-D 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 temperatures of the year. Your program must consist of the following methods with their appropriate parameters: a.) getData: This method reads and stores the data in the 2-D array. b.) averageHigh: This method calculates and returns the average high temperature of the year. c.)...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In c++ Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value). The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In c++ Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value). The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In C++ c. The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function indexLowTemp: This function returns the index of the lowest low temperature in the array. These functions must all have the appropriate parameters.
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT