Explian with comments on each line what the source codedoes
Create UML
Create Flowchart
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 ];
}
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
String monthNames[] ={“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Spe”,”Oct”,”Nov”,”Dec”};
double monRainfall[] = {0.40, 0.94, 3.21, 3.74, 1.73, 1.03, 1.27,2.58, 6.98, 6.90, 2.80, 2.53};
System.out.println(“Austin Tx Rainfall 2009”);
System.out.println(“—————————“);
for(int i = 0; i < monthNames.length; i++)
{
System.out.println(monthNames[i]+” “+monRainfall[i]);
}
System.out.println();
System.out.println(“Total : “+totalRainfall(monRainfall));
System.out.println(“Average :”+averageRainfall(monRainfall));
System.out.println(“Max : “+maxRainfall(monRainfall));
System.out.println(“Min : “+minRainfall(monRainfall));
}
}
Answer