Question: Java coding Rolling Average In the past coupe of years, plots like the two shown below have become very common on the Internet. The left
Java coding
Rolling Average In the past coupe of years, plots like the two shown below have become very common on the Internet. The left is the result of a Google search for covid numbers ottawa, and the one the right is from cbc.ca. In these plots, both the raw data and the rolling average of that data (taken over 7 days) is included. The rolling average is present to highlight the overall trends of the data that might not be clear from the raw data. For example, consider the data for one month shown below. Looking carefully at the dates (they correspond to August 2021), you will see that the new case counts were zero over each weekend of the month (Saturday and Sunday) and that most Mondays had a significantly large count than the rest of the days of the week. The absence of cases on some days and then the jump in numbers after them make sense when you take some time to consider what is happening. The rolling average (using a 7-day average and shown as the continuous line), however, clearly shows a consistent slow increase in numbers over the month. The rolling average quickly communicates the overall trend in the data without having to consider what the gaps and jumps mean. The rolling average (also called a moving average or running average) for any given day is the average of that days count along with the 6 previous days for a 7-day average. (Note that there are other ways of computing a 7-day average in which you use the current days value along with the values from the 3 previous days and the next 3 days. We will only use the current day and
some previous days in this assignment.) A rolling average does not have to use 7 values for the average in general but it is common when the data corresponds to days of the week. In the provided A1Q1.java file, complete the rollingAverage() method. This method will compute the rolling average of some data using a specified width (number of data points used for the average). This method takes an array of floating point numbers (called data) and an integer (called width) as input. The method returns a new array that is the same size as the input array and will contain the rolling average of the input array data using width data points for each value. public static double[] rollingAverage(double[] data, int width) For each position where there is not enough data points (width) to compute the average, you will use the NaN (Not-A-Number) value. In particular, the first width1 elements of the output array should have this value. Here are some examples: A1Q1.rollingAverage(new double[]{1,2,4}, 1) -> [1.0, 2.0, 4.0] A1Q1.rollingAverage(new double[]{1,2}, 2) -> [NaN, 1.5] A1Q1.rollingAverage(new double[]{1,2,4,9}, 3) -> [NaN, NaN, 2.3333333333333335, 5.0] A1Q1.rollingAverage(new double[]{1,2,4}, 4) -> [NaN, NaN, NaN] You will need to investigate and use Javas Double class to learn more about the value NaN. In future assignments, restrictions on the input arguments passed to methods you create will be provided as preconditions for the methods. For this assignment, they are listed here (as well as in the provided java file). Note that no testing will involve input data that violates these restrictions. data: 0 <= data.length <= Integer.MAX_VALUE/100 size: 1 <= width <= Integer.MAX_VALUE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
