Rainfall.java - import javax.swing.JOptionPane public class...

  • No School
  • AA 1
  • 2
  • 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1 - 2 out of 2 pages.

import javax.swing.JOptionPane; public class Rainfall { double [] rainfallStats; public double getTotalRainfall() { double totalRainfall = 0; for(int index = 0; index < rainfallStats.length; index++) { totalRainfall = totalRainfall + rainfallStats[index]; } return totalRainfall; } public double getAverageRainfall() { return getTotalRainfall() / rainfallStats.length; } public int getMostRainMonth() { double mostRain = rainfallStats[0]; int mostRainMonth = 1; for(int index = 0; index < rainfallStats.length; index++) { if(rainfallStats[index] > mostRain) { mostRain = rainfallStats[index]; mostRainMonth = index + 1; } } return mostRainMonth; } public int getLeastRainMonth() { double leastRain = rainfallStats[0]; int leastRainMonth = 1; for(int index = 0; index < rainfallStats.length; index++) { if(rainfallStats[index] < leastRain) { leastRain = rainfallStats[index]; leastRainMonth = index + 1; } } return leastRainMonth; } public Rainfall(double [] rainfallStatsGiven) { rainfallStats = new double[rainfallStatsGiven.length]; for(int index = 0; index < rainfallStatsGiven.length; index++) { rainfallStats[index] = rainfallStatsGiven[index];
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

  • Fall '19
  • Cybernetics, Rain, public class Rainfall, public double getTotalRainfall

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture