Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program (class and demo) with this UML RainFall - rain: double[] +RainFa

ID: 3641673 • Letter: W

Question

Write a program (class and demo) with this UML

RainFall

- rain: double[]

+RainFall(r:double[])

+getTotalRainFall(): double

+getAverageRainFall(): double

+getHighestMonth(): double

+getLowestMonth(): double

+getRainAt(int e): double


//1. create your new array

//2. Copy the argument’s elements to the new array, I recommend using for loop

+getTotalRainFall(): double

//initialized the Accumulator

//Accumulate the sum of the rain array elements, I recommend for loop

//return total


+getAverageRainFall(): double

// return the total divide the length of the rain array

+getHighestMonth(): double

// declare and initialize highest to zero

//Find the element with the highest value

//return highest;

doesn't require user to input rainfall amount for each month, but you have to create your own data (any number will do) the have the program read from that data
_________________________
Output
The total rainfall for this year is...........
The average rainfall for this year is .............
The month with the highest amount of rain is ... with ..... inches.
The month with the lowest amount of rain is ... with ..... inches.











Explanation / Answer

import java.util.Arrays; public class RainFall { public RainFall(double[] r) { for (int i = 0; i < 10; i++) { r[i] = Math.random()*100; } } public double getTotalRainFall(double[] rain) { double total = 0.0; for (int i = 0; i < 10; i++) { total = total + rain[i]; } return total; } double getAverageRainFall(double[] rain) { double total = getTotalRainFall(rain); double avg = total / rain.length; return avg; } double getHighestMonth(double[] rain) { Arrays.sort(rain); return rain[rain.length-1]; } double getLowestMonth(double[] rain) { Arrays.sort(rain); return rain[0]; } double getRainAt(int e) { return 0; } public static void main(String args[]) { double[] rain = new double[10]; RainFall rainFall = new RainFall(rain); double totalRainFall = rainFall.getTotalRainFall(rain); System.out.println("The total rainfall for this year is..........." + totalRainFall); double avgRainFall = rainFall.getTotalRainFall(rain); System.out.println("The average rainfall for this year is..........." + avgRainFall); double highestRainFall = rainFall.getHighestMonth(rain); System.out.println("The month with the highest amount of rain is ... with ..... inches"+highestRainFall); double lowestRainFall= rainFall.getLowestMonth(rain); System.out.println("The month with the lowest amount of rain is ... with ..... inches."+lowestRainFall); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote