Question: The goal of this assignment is to write a program, RainQuery, that reads a historical precipitation record of London from 1931 to 2013 and then
The goal of this assignment is to write a program, RainQuery, that reads a historical precipitation record of London from 1931 to 2013 and then compute statistics interactively with the user. Let us see some execution examples first, to get the sense of how the program works.
% java RainQuery You can query the database 1. Daily value 2. Range statistic 3. Day statistics 4. Day of the month statistics 0. Quit Enter your choice: 1 Enter year, month, day 1971 1 1 The value is 1.13. You can query the database 1. Daily value 2. Range statistic 3. Day statistics 4. Day of the month statistics 0. Quit Enter your choice: 2 Enter start year, month, day 1972 1 1 Enter end year, month, day 1974 12 31 Total 1096 points, average=3.409, maximum=31.52, minimum=0.00. You can query the database 1. Daily value 2. Range statistic 3. Day statistics 4. Day of the month statistics 0. Quit Enter your choice: 3 Enter month and day 12 31
Total 83 points, average=5.007, maximum=22.97, minimum=0.00. You can query the database 1. Daily value 2. Range statistic
3. Day statistics 4. Day of the month statistics 0. Quit Enter your choice: 4 Enter day 2 Total 986 points, average=4.034, maximum=30.16, minimum=0.00. You can query the database 1. Daily value 2. Range statistic 3. Day statistics 4. Day of the month statistics 0. Quit Enter your choice: 0 %
The data
The data is provided in a file precipitation.txt attached to this assignment. You must download it into the directory in which you are writing the code. Each line of the data file is in the following format:
YEAR MONTH VALUE1 ... VALUE31
VALUE1 through VALUE31 represent the values for the 31 days of the month of the year. For months with fewer than 31 days, 99.0 as the values for the non-existing dates. Since any actual precipitation value is nonnegative, the sign attached to this special value clearly indicates the absence of data. The lines appear in the increasing order of year and month. Because of this format, each year has 12 31 = 372 entries. We will read values from the file and store them in a one-dimensional array of double ignoring the year and month values. Here are the first 12 lines with the first 4 and the last 4 for the days entries:

1931 11 6.71 19.67 15.97 3.59 ... 5.00 1.18 0.93 -99.99
1931 12 2.37 20.05 14.05 6.14 ... 5.46 3.41 1.21
Constants
We will use the following constants in the program.
public static final String FILENAME = "precipitation.txt"; public static final int FIRST_YEAR = 1931; public static final int LAST_YEAR = 2013; public static final int YEAR_SIZE = 12 * 31;
public static final int N_YEARS = LAST_YEAR - FIRST_YEAR + 1; public static final int FULL_SIZE = N_YEARS * YEAR_SIZE;
14.45
Note that YEAR SIZE represents the number of entries per year, N YEARS represents the number of years covered by the data, and FULL SIZE represents the total number of data, and this is the length of the one-dimensional array.
Method readData Write a method, readData, that reads data from the data file and returns an array of double that
contains the data.
Method join
Once the values have been read into an array, the value on a specific date can be obtained by examining the data, where index 0 corresponds to January 1st, 1931, index 31 corresponds to February 1st, 1931, index YEAR SIZE corresponds corresponds to January 1st, 1932, etc. We use a method, join, that returns this index given the three values as its parameters. The method should be so designed that if any of of the three quantities is out of range (that is, the years is out of range, the month is out of range, or the day is out of range), it returns a negative value.
Method showStats
Once the methods for reading data and for querying the data have been written, we can write an interactive program to receive requests from the user and provides information. We envision that there will be four different types of queries:
The value on one specific date: show the value of the data specified by the year, the month, and the day.
The statistics of data between two specific dates: show the maximum, the minimum, and the average over a period of time, along with the total of number of data points, where the start and the end dates are each specified by the year, the month, and the day
A specific day of year: show the maximum, the minimum, and the average of a specific day of a year, along with the total number data points, where the day of year is specified by its month and day
A specific day of month: show the maximum, the minimum, and the average of a specific day of any month, along with the total number data points
All these queries can be processed using a method, showStatistics, that receives four parameters, a double[] named data, an int named start, an int named end, and an int named increment, and produces on the screen the number of data points, the average, the maximum, and the minimum in the range of indexes between start and end such that the index values are of the formstart + increment * i for some i. Each index value can be computed from the year, the month, and the day using the method join. The value of increment can be 1 for Tasks 1 and 2, YEAR SIZE for Task 3, and 31 for Task 4. To compute the maximum and the minimum, we can set their initial values to some negative value and some gigantic positive value. Inside showStatistics, we will run a for-loop that iterates over a series of indexes starting from start covering all values no more than end with the update by adding increment, while using only those indexes at which the value is nonnegative, where we compute the number of points, the total, the maximum, and the minimum. The loop should be run only if both start and end are positive and increment is positive. After computing the four quantities, the method should report the results only if the count is positive. In addition, the average, the maximum, and the minimum should be reported only if the count is greater than 1.
Attached: (Sorry, I did not find how to upload attachment. You can copy it and save it as a txt. file to use it. )
1931 1 4.13 1.79 2.21 0.94 0.08 0.03 0.42 6.30 1.95 3.87 4.35 2.06 1.05 2.89 7.26 16.13 1.35 10.85 3.69 0.74 5.52 14.43 13.32 4.50 3.03 1.79 3.06 6.46 1.32 4.46 19.17 1931 2 3.18 1.94 0.58 2.99 7.36 3.10 7.34 4.35 7.09 7.00 20.06 2.43 0.72 5.08 6.05 3.95 1.93 1.23 5.70 8.39 3.34 4.82 3.14 7.87 3.82 1.90 1.84 4.06 -99.99 -99.99 -99.99 1931 3 0.82 2.67 0.19 0.24 0.26 0.85 1.18 0.81 3.45 1.22 0.52 4.69 4.85 0.26 0.45 0.08 0.00 0.16 4.15 3.35 1.79 1.48 0.18 0.00 0.00 0.03 2.25 0.14 1.24 0.23 0.11 1931 4 3.37 6.04 0.59 3.42 0.29 0.00 1.06 3.03 0.03 0.84 3.33 2.38 1.38 2.04 3.01 7.55 4.72 0.29 0.84 0.66 2.56 2.90 3.20 5.38 4.87 3.12 3.96 0.48 0.19 3.16 -99.99 1931 5 2.64 0.69 3.70 0.56 4.18 0.67 7.44 0.33 7.42 9.39 3.41 1.69 8.24 9.22 2.59 3.80 0.79 0.45 0.54 0.24 0.00 2.42 1.96 7.08 4.04 0.85 0.05 15.53 1.15 4.92 13.28 1931 6 3.53 8.30 2.41 0.20 2.49 9.82 2.11 4.26 8.94 9.98 0.51 0.41 8.61 37.31 13.22 1.60 6.80 6.37 0.58 3.66 5.88 1.28 1.41 0.00 0.45 2.53 1.17 1.32 1.17 1.38 -99.99 1931 7 7.38 1.21 6.02 2.57 4.39 12.67 2.77 2.28 1.84 0.60 5.38 3.95 2.03 6.31 1.16 3.54 6.37 2.63 2.49 0.33 5.26 9.03 1.81 3.20 8.80 15.50 9.45 4.44 6.50 2.23 1.11 1931 8 0.26 0.03 0.00 0.05 0.05 0.63 3.51 1.10 5.30 0.31 0.93 2.19 0.51 1.98 1.49 2.82 10.54 1.58 17.54 10.60 1.14 1.03 0.80 0.08 1.82 0.05 0.00 0.00 0.00 0.00 0.05 1931 9 11.13 4.81 2.01 0.73 1.21 1.50 1.19 3.48 0.56 1.36 3.79 0.08 0.71 0.68 0.42 11.14 0.26 0.98 0.12 0.05 0.00 0.11 0.34 0.12 0.03 0.03 0.24 0.00 3.00 4.72 -99.99 1931 10 16.46 7.33 2.56 8.18 5.00 7.83 9.02 4.41 5.70 2.48 4.00 2.98 0.78 0.08 0.05 0.09 0.20 0.08 1.60 1.11 0.37 1.97 4.72 0.87 1.33 3.66 13.37 1.39 8.38 0.45 4.16 1931 11 6.71 19.67 15.97 3.59 1.68 3.79 7.31 2.63 6.28 7.63 3.02 0.96 7.47 10.94 0.06 0.20 12.14 11.67 3.92 6.87 2.87 8.81 29.22 5.20 9.16 9.56 3.59 5.00 1.18 0.93 -99.99 1931 12 2.37 20.05 14.05 6.14 5.15 2.55 5.74 4.60 4.78 1.01 1.31 0.88 1.95 2.45 0.03 0.25 0.06 3.29 1.21 0.47 0.38 7.82 12.39 4.65 1.32 1.81 5.96 5.46 3.41 1.21 14.45 1932 1 10.69 26.46 13.09 7.73 10.48 5.78 1.34 1.46 20.57 3.54 0.98 12.41 6.35 22.80 19.44 6.26 4.05 4.13 12.66 2.56 4.86 1.01 0.58 3.94 0.12 0.16 0.03 2.01 0.27 0.25 1.77 1932 2 0.14 0.90 0.30 0.31 0.23 0.13 0.03 0.69 0.97 0.28 0.68 0.41 0.38 0.11 0.24 0.05 0.08 0.25 0.30 0.14 0.40 0.46 0.55 0.39 0.28 0.13 0.25 0.11 0.05 -99.99 -99.99 1932 3 0.14 0.03 0.08 2.63 7.68 5.63 6.49 1.21 0.90 1.21 0.54 1.43 0.67 0.29 0.08 0.35 0.08 0.58 2.30 9.85 12.73 5.89 1.53 5.63 1.18 0.77 5.30 0.86 7.41 11.65 2.14 1932 4 6.35 9.11 1.66 0.60 9.97 7.81 4.02 12.51 13.69 6.27 2.83 0.67 9.05 3.55 1.13 0.05 0.26 0.54 4.48 3.29 1.03 10.28 4.31 0.83 0.27 1.01 3.14 8.40 2.12 1.05 -99.99 1932 5 0.17 0.08 0.05 1.37 2.32 2.20 1.53 0.97 1.68 0.43 6.92 18.64 4.08 1.06 14.01 1.89 0.38 6.31 6.22 2.55 1.23 0.26 1.17 1.20 7.75 2.39 0.86 1.79 0.75 0.98 0.00 1932 6 0.03 0.00 0.08 0.72 0.19 0.08 0.86 0.13 0.73 0.27 0.30 0.04 0.00 0.04 0.52 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.49 1.02 2.09 4.48 6.75 1.38 7.22 15.37 -99.99 1932 7 1.80 6.01 13.47 7.08 1.82 0.98 1.51 4.06 2.85 3.13 0.96 2.25 3.76 0.00 2.66 1.17 1.58 0.33 2.85 3.66 6.61 2.30 5.04 5.42 2.95 6.43 10.99 2.14 9.29 9.30 6.52
1931 1931 1931 1931 1931 1931 1931 1931 1931 1931 10 16.467.33 2.56 8.18 1 4.13 1.792.21 0.94 23.18 1.940.58 2.99 3 0.82 2.67 0.19 0.24 4 3.37 6.040.59 3.42 5 2.64 0.693.70 0.56 6 3.53 8.30 2.41 0.20 7 7.38 1.21 6.02 2.57 8 0.26 0.03 0.00 0.05 9 11.13 4.81 2.01 0.73 6.46 1.32 4.46 19.17 4.06 -99.99 -99.99 -99.99 0.141.240.23 0.11 0.480.19 3.16 -99.99 15.53 1.15 4.92 13.28 1.32 1.17 1.38 -99.99 4.44 6.50 2.23 1.11 0.000.00 0.00 0.05 0.003.004.72 -99.99 1.398.38 0.45 4.16 1931 1931 1931 1931 1931 1931 1931 1931 1931 1931 10 16.467.33 2.56 8.18 1 4.13 1.792.21 0.94 23.18 1.940.58 2.99 3 0.82 2.67 0.19 0.24 4 3.37 6.040.59 3.42 5 2.64 0.693.70 0.56 6 3.53 8.30 2.41 0.20 7 7.38 1.21 6.02 2.57 8 0.26 0.03 0.00 0.05 9 11.13 4.81 2.01 0.73 6.46 1.32 4.46 19.17 4.06 -99.99 -99.99 -99.99 0.141.240.23 0.11 0.480.19 3.16 -99.99 15.53 1.15 4.92 13.28 1.32 1.17 1.38 -99.99 4.44 6.50 2.23 1.11 0.000.00 0.00 0.05 0.003.004.72 -99.99 1.398.38 0.45 4.16
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
