Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1.  
  2. /**
  3. * Write a description of class rainfallData here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class RainfallData
  9. {
  10. // place where rainfall is recorded
  11. private String location;
  12. // declare array to store 12 months of data in centimetres
  13. private double[] rainfall;
  14.  
  15. /**
  16. * Constructor for objects of class rainfallData
  17. */
  18. public RainfallData(String l)
  19. {
  20. // store location of measurement
  21. location = l;
  22. // create array
  23. rainfall = new double[12];
  24. }
  25.  
  26. /**
  27. * return Location
  28. */
  29. public String getLocation()
  30. {
  31. return location;
  32. }
  33.  
  34. /**
  35. * Method to add one month's data into the array.
  36. *
  37. * @param month Month in the year (January = 1, February = 2 etc.).
  38. * @param amount The amount of rain (in centimetres) that fell that month
  39. */
  40. public void enterData(int month, double amount)
  41. {
  42. rainfall[month-1] = amount;
  43. }
  44.  
  45. /**
  46. * Method to calculate the average monthly rainfall for the location.
  47. *
  48. * @return Average monthly rainfall (centimetres)
  49. */
  50. public double monthlyAverage()
  51. {
  52. double total = 0;
  53. double average = 0;
  54. for(int i = 0; i < rainfall.length; i++)
  55. {
  56. total = total + rainfall[i];
  57. }
  58. average = total / rainfall.length;
  59. return average;
  60. }
  61.  
  62. /**
  63. * Method to calculate the heaviest monthly rainfall for the location.
  64. *
  65. * @return Heaviest monthly rainfall (centimetres)
  66. */
  67. public double heaviestAmount()
  68. {
  69. double max = 0;
  70. for(int i = 0; i < rainfall.length; i++)
  71. {
  72. if(max < rainfall[i])
  73. {
  74. max = rainfall[i];
  75. }
  76. } // complete this and modify the return statement below
  77. return max;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement