Question

In: Computer Science

How’s the Weather Purpose To enhance your ability to properly index and retrieve items in an...

How’s the Weather

Purpose

To enhance your ability to properly index and retrieve items in an array in Java

Directions and examples:

The FAS 2720 class this semester was tasked with writing a research paper on temperature change and its effect on crops. A student comes to you for help, and asks if you can make him some software that will compute the average temperatures throughout a five-day period. Write a program that prompts the user for all of the temperatures over the five-day period (sunrise, noon and sunset for each day), then compute and display the average temperature on each day of the week, and the average temperature at sunrise, noon, and sunset across all five days.

Output:

Day 1:

Enter Sunrise Temperature: 65

Enter Noon Temperature: 75

Enter Sunset Temperature: 63

Day 2:

Enter Sunrise Temperature: 68

Enter Noon Temperature: 85

Enter Sunset Temperature: 70

Day 3:

Enter Sunrise Temperature: 60

Enter Noon Temperature: 70

Enter Sunset Temperature: 65

Day 4:

Enter Sunrise Temperature: 69

Enter Noon Temperature: 90

Enter Sunset Temperature: 73

Day 5:

Enter Sunrise Temperature: 70

Enter Noon Temperature: 89

Enter Sunset Temperature: 76

Day 1 Average = 67.66666666666667

Day 2 Average = 74.33333333333333

Day 3 Average = 65.0

Day 4 Average = 77.33333333333333

Day 5 Average = 78.33333333333333

Sunrise Average = 66.4

Noon Average = 81.8

Sunset Average = 69.4

Solutions

Expert Solution

import java.util.*;

public class Main
{
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            //2D matrix where row represents days and columns represents 3 periods
                int[][] temp = new int[5][3];
                
                //user input for 5 day and 3 periods for each and stores it in 2D matrix
                for(int i = 0; i < 5; i++)
                {
                    System.out.println("Day " + (i+1) + ":");
                    for(int j = 0; j < 3; j++)
                    {
                        if(j==0)
                            System.out.print("Enter Sunrise Temperature: ");
                        if(j==1)
                            System.out.print("Enter Noon Temperature: ");
                        if(j==2)
                            System.out.print("Enter Sunset Temperature: ");
                        temp[i][j] = sc.nextInt();
                    }
                }
                
                //calculates average of 5 days
                for (int i = 0; i < 5; i++)
        {
            double rowSum = 0;
            //calculates sum of row means days
            for (int j = 0; j < 3; j++)
            {
                rowSum += temp[i][j];
            }
            System.out.println("Day " + (i+1) + " Average " + rowSum / 3);
        }
        
        //calculates average of 3 periods
        for (int i = 0; i < 3; i++)
        {
            double columnSum = 0;
            //calculates sum of column means periods
            for (int j = 0; j < 5; j++)
            {
                columnSum += temp[j][i];
            }
            if(i==0)
                    System.out.println("Sunrise Average: " + columnSum / 5);
                if(i==1)
                    System.out.println("Noon Average: " + columnSum / 5);
                if(i==2)
                    System.out.println("Sunset Average: " + columnSum / 5);
        }
        }
}

Please refer below screenshot of code for your better understanding of indentation of code.

Sample Output :


Related Solutions

Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability to identify emerging ethical issues in business, interpret the multitude of perspectives inherent in your case study, and model appropriate behaviour by recommending specific solutions. How to Proceed Select a case. It can be one of the textbook cases that we have not discussed during the course. It can also come from the outside world, perhaps a case you have been following in the...
The purpose of this assignment is to enhance your writing, application of knowledge, and critical thinking...
The purpose of this assignment is to enhance your writing, application of knowledge, and critical thinking skills. In general, this assignment requires you to analyze an organization of your choice and prepare a case study covering a variety of aspects of the organization. The content will include information on the mission, strategy, culture, structure, and environment of the organization. First you need to choose an organization to examine. It can be one you worked for in the past, your present...
PURPOSE: The purpose of this assignment is to enable the students to enhance their knowledge on...
PURPOSE: The purpose of this assignment is to enable the students to enhance their knowledge on the environmental engineering and sustainable development for environmental engineering. TASK 1 (DOCUMENTATION) Development in science and technology has increase the level of human lifestyle which leads to technology advancement. However, everything good comes with a price. One of the greatest problems that the world is facing today is that of environmental pollution, increasing with every passing year and causing grave and irreparable damage to...
QUESTION 1 Explain how theories of accounting enhance your ability to be a critical thinker and...
QUESTION 1 Explain how theories of accounting enhance your ability to be a critical thinker and differentiate you from an average accountant.                                                                                       Explain the philosophical foundations and main arguments of critical accounting research.                                                                                                                                                                                                                                                                                                                                     Question 2          (a)    Describe the basic features of positive and normative theories of accounting. Give examples of these theories.                                                                                                                      (3 marks) (b)   Differentiate Positive Accounting Theory (PAT) from other positive theories of accounting.                                                                                                                                                                          (5 marks) (c)...
PLEASE answer ALL questions to the best of your ability: You would like to enhance the...
PLEASE answer ALL questions to the best of your ability: You would like to enhance the HR analytics capabilities in your organization by hiring an HR analytics specialist who will help you better collect, analyze, and report on key HR analytics. At the company’s next executive meeting, you need to make the case to the CEO, the CFO, and the CTO about why this is a good investment. What will you and the HR analytics specialist be measuring? What measurement...
The purpose of this assignment is to develop your ability to code and understand ArrayLists. We...
The purpose of this assignment is to develop your ability to code and understand ArrayLists. We will do this by taking a do-it-yourself (DIY) approach by building our own ArrayList-Like data structure called "ArrayBox". You must: Create a generic class called ArrayBox that uses an ARRAY to store its objects. Assume the initial size of the array is two(2). Your ArrayBox must automatically double the size of your elements array when it becomes full as described in class (see slides)....
Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret...
Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret detailed policy. We have chosen for you to take a look at two of the most well known policies; in real life, you will have government polices such as these as well as enterprise specific policies or regulations. As you build information systems, it is key to early on in the process to identify all relevant policy drivers and understand them. In the module,...
The color of the eyes in plutonians is very important for their ability to properly see...
The color of the eyes in plutonians is very important for their ability to properly see the objects in pluto. To determine the color of the eyes on early stages of development a test was developed using STRs. There is an allele containing 10 repeats of 200nt and another one with 6 repeats. Plutonian with black eyes and 10/10 repeats had children with a female with orange eyes and 6/6 repeats. Their progeny was crossed with arecessive individual with 6/6...
Its purpose is to provide you an opportunity to demonstrate your ability to think like an...
Its purpose is to provide you an opportunity to demonstrate your ability to think like an economist by applying economic principles to interpret the logic of a real-world phenomenon. Please identify any ONE of the monetary policies during COVID 19 in the world, use macroeconomic theories to demonstrate the economic logic behind this monetary policy. Also, please discuss how different schools of economics think of this monetary policy. Do you agree or disagree with this monetary policy? Please use the...
Its purpose is to provide you an opportunity to demonstrate your ability to think like an...
Its purpose is to provide you an opportunity to demonstrate your ability to think like an economist by applying economic principles to interpret the logic of a real-world phenomenon. Please identify any ONE of the monetary policies during COVID 19 in the world, use macroeconomic theories to demonstrate the economic logic behind this monetary policy. Also, please discuss how different schools of economics think of this monetary policy. Do you agree or disagree with this monetary policy? Please use the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT