Rainfall Data Program . In the Main.java file create a program that • Reads rainfall information from the rainfallData.c
Posted: Sat May 14, 2022 8:15 pm
Code for the Rainfall Class
import java.util.Arrays;
import java.util.Scanner;
public class RainFall
{
public static double totalRainfall(double[] rainfall)
{
double total = 0;
for(double d : rainfall)
{
total += d;
}
return total;
}
public static double averageRainfall(double[]
rainfall)
{
double total = totalRainfall(rainfall);
return total/rainfall.length;
}
public static double minRainfall(double[]
rainfall)
{
// sorting the array
Arrays.sort(rainfall);
return rainfall[0];
}
public static double maxRainfall(double[]
rainfall)
{
// sorting the array
Arrays.sort(rainfall);
return rainfall[ rainfall.length - 1 ];
}
Rainfall Data Program . In the Main.java file create a program that • Reads rainfall information from the rainfallData.csv file. o the file includes data of monthly rainfall totals in millimeters (mm) for several years. o open the file and get a sense of its content For each year of data (each year found in the data file (rainfallData.csv)) your program should: o use the getYearlyTotal method and prints out the total rainfall for that year o use the getMonthly Avg method and prints out the average monthly rainfall for that year o use the getHighestMonth method and prints out the month number (1,2,.,12) with the highest total rainfall o use the getLowestMonth method and prints out the month number (1,2,.,12) with the lowest total rainfall Make sure you add the suitable exception handling blocks i.e., try and catch blocks when dealing with input from a file.
import java.util.Arrays;
import java.util.Scanner;
public class RainFall
{
public static double totalRainfall(double[] rainfall)
{
double total = 0;
for(double d : rainfall)
{
total += d;
}
return total;
}
public static double averageRainfall(double[]
rainfall)
{
double total = totalRainfall(rainfall);
return total/rainfall.length;
}
public static double minRainfall(double[]
rainfall)
{
// sorting the array
Arrays.sort(rainfall);
return rainfall[0];
}
public static double maxRainfall(double[]
rainfall)
{
// sorting the array
Arrays.sort(rainfall);
return rainfall[ rainfall.length - 1 ];
}
Rainfall Data Program . In the Main.java file create a program that • Reads rainfall information from the rainfallData.csv file. o the file includes data of monthly rainfall totals in millimeters (mm) for several years. o open the file and get a sense of its content For each year of data (each year found in the data file (rainfallData.csv)) your program should: o use the getYearlyTotal method and prints out the total rainfall for that year o use the getMonthly Avg method and prints out the average monthly rainfall for that year o use the getHighestMonth method and prints out the month number (1,2,.,12) with the highest total rainfall o use the getLowestMonth method and prints out the month number (1,2,.,12) with the lowest total rainfall Make sure you add the suitable exception handling blocks i.e., try and catch blocks when dealing with input from a file.