Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class rainfallData here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class RainfallData
- {
- // place where rainfall is recorded
- private String location;
- // declare array to store 12 months of data in centimetres
- private double[] rainfall;
- /**
- * Constructor for objects of class rainfallData
- */
- public RainfallData(String l)
- {
- // store location of measurement
- location = l;
- // create array
- rainfall = new double[12];
- }
- /**
- * return Location
- */
- public String getLocation()
- {
- return location;
- }
- /**
- * Method to add one month's data into the array.
- *
- * @param month Month in the year (January = 1, February = 2 etc.).
- * @param amount The amount of rain (in centimetres) that fell that month
- */
- public void enterData(int month, double amount)
- {
- rainfall[month-1] = amount;
- }
- /**
- * Method to calculate the average monthly rainfall for the location.
- *
- * @return Average monthly rainfall (centimetres)
- */
- public double monthlyAverage()
- {
- double total = 0;
- double average = 0;
- for(int i = 0; i < rainfall.length; i++)
- {
- total = total + rainfall[i];
- }
- average = total / rainfall.length;
- return average;
- }
- /**
- * Method to calculate the heaviest monthly rainfall for the location.
- *
- * @return Heaviest monthly rainfall (centimetres)
- */
- public double heaviestAmount()
- {
- double max = 0;
- for(int i = 0; i < rainfall.length; i++)
- {
- if(max < rainfall[i])
- {
- max = rainfall[i];
- }
- } // complete this and modify the return statement below
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement