Question

In: Computer Science

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

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. These methods MUST be your original code.   Your program should output all the values in the array and then output the average high and the average low.

Remember to submit all your .java files, .class files and screenshots of your code and output.

Solutions

Expert Solution

//RainFall.java
import java.util.Scanner;
public class RainFall {
    public static double averageLow(double arr[][]){
        double sum = 0;
        for(int i = 0;i<12;i++){
            sum += arr[i][0];
        }
        return sum/12;
    }

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

    public static void main(String[] args) {
        double arr[][] = new double[12][2];
        Scanner scanner = new Scanner(System.in);

        for(int i = 0;i<12;i++) {
            System.out.print("Enter low temperature for month " + (i+1)+": ");
            arr[i][0] = scanner.nextDouble();
            System.out.print("Enter high temperature for month " + (i+1)+": ");
            arr[i][1] = scanner.nextDouble();
        }

        System.out.println("Month\tLow\t\tHigh");
        for(int i = 0;i<arr.length;i++){
            System.out.print((i+1)+"\t");
            for(int j = 0;j<arr[i].length;j++){
                System.out.print(arr[i][j]+"\t\t");
            }
            System.out.println();
        }

        System.out.println("Average high temperatures = "+averageHigh(arr));
        System.out.println("Average low temperatures = "+averageLow(arr));
    }
}

Enter low temperature for month 1: 1
Enter high temperature for month 1: 2
Enter low temperature for month 2: 3
Enter high temperature for month 2: 4
Enter low temperature for month 3: 5
Enter high temperature for month 3: 6
Enter low temperature for month 4: 7
Enter high temperature for month 4: 8
Enter low temperature for month 5: 9
Enter high temperature for month 5: 12
Enter low temperature for month 6: 34
Enter high temperature for month 6: 56
Enter low temperature for month 7: 78
Enter high temperature for month 7: 98
Enter low temperature for month 8: 12
Enter high temperature for month 8: 23
Enter low temperature for month 9: 34
Enter high temperature for month 9: 45
Enter low temperature for month 10: 56
Enter high temperature for month 10: 67
Enter low temperature for month 11: 78
Enter high temperature for month 11: 89
Enter low temperature for month 12: 76
Enter high temperature for month 12: 99
Month   Low           High
1     1.0           2.0
2     3.0           4.0
3     5.0           6.0
4     7.0           8.0
5     9.0           12.0
6     34.0      56.0      
7     78.0      98.0      
8     12.0      23.0      
9     34.0      45.0      
10    56.0      67.0      
11    78.0      89.0      
12    76.0      99.0      
Average high temperatures = 42.416666666666664
Average low temperatures = 32.75

Process finished with exit code 0

Related Solutions

Write a program that uses a two dimensional array to store the highest and lowest temperatures...
Write a program that uses a two dimensional array to store the highest and lowest temperatures for each month of the calendar year. The temperatures will be entered at the keyboard. This program must output the average high, average low, and highest and lowest temperatures of the year. The results will be printed on the console. The program must include the following methods: A method named inputTempForMonth whose purpose is to input a high and a low temperature for a...
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...
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.
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.)...
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 that uses an array of high temperatures for your hometown from last week...
Write a program that uses an array of high temperatures for your hometown from last week (Sunday – Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array as a parameter and then creates...
Write a program that uses an array of high temperatures for your hometown from last week...
Write a program that uses an array of high temperatures for your hometown from last week (Sunday – Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array as a parameter and then creates...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT