Advertisement
Ccuevas3410

Rainfall

Sep 12th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication1;
  7.  
  8. import java.util.Scanner;
  9.  
  10. public class RainFall {
  11.  
  12. /**
  13. * @param args the command line arguments
  14. */
  15. static double total = 0;
  16. public static double monthsOfRainfall[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
  17.  
  18. public static String monthsNames[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
  19.  
  20. public static void main(String[] args) {
  21.  
  22. yearlyRainfall();
  23. averageMonthlyRainfall();
  24. highestMonth();
  25. lowestMonth();
  26. }
  27.  
  28. public static void yearlyRainfall() {
  29.  
  30. Scanner input = new Scanner(System.in);
  31.  
  32. for (int i = 0; i < monthsOfRainfall.length; i++) {
  33.  
  34. System.out.println("Enter the rainfall for month " + (monthsNames[i]));
  35.  
  36. monthsOfRainfall[i] = input.nextDouble();
  37.  
  38. if (monthsOfRainfall[i] < 0) {
  39. i--;
  40. System.out.println("Error, Invalid Input. Re-Enter integer between 0 and ∞.");
  41. } else {
  42.  
  43. total += monthsOfRainfall[i];
  44. }
  45.  
  46. }
  47. System.out.println("*********************************");
  48. System.out.println("The total rainfall for the year is: " + total);
  49.  
  50. System.out.println("*********************************");
  51.  
  52. }
  53. //METHOD TO KNOW THE AVERAGE RAIN IN X MONTH
  54.  
  55. public static void averageMonthlyRainfall() {
  56.  
  57. System.out.println("The average monthly Rainfall is " + total / 12);
  58. System.out.println("*********************************");
  59.  
  60. }
  61. //METHOD TO KNOW THE HIGHEST RAIN MONTH
  62.  
  63. public static void highestMonth() {
  64.  
  65. double highest = monthsOfRainfall[0];
  66.  
  67. String whatmonth = monthsNames[0];
  68. int i;
  69.  
  70. for (i = 0; i < monthsOfRainfall.length; i++) {
  71.  
  72. if (monthsOfRainfall[i] > highest) {
  73. whatmonth = monthsNames[i];
  74. highest = +monthsOfRainfall[i];
  75.  
  76. }
  77.  
  78. }
  79. System.out.println("The Highest month is " + whatmonth + " with a rainfall of: " + highest);
  80. }
  81.  
  82. //METHOD TO KNOW THE LOWWEST RAIN MONTH
  83. public static void lowestMonth() {
  84.  
  85. double lowest = monthsOfRainfall[0];
  86. String whatmonth = monthsNames[0];
  87. int i;
  88.  
  89. for (i = 0; i < monthsOfRainfall.length; i++) {
  90.  
  91. if (monthsOfRainfall[i] < lowest) {
  92. whatmonth = monthsNames[i];
  93. lowest = monthsOfRainfall[i];
  94. }
  95.  
  96. }
  97.  
  98. System.out.println("*********************************");
  99. System.out.println("The Lowest month is " + whatmonth + " with a rainfall of: " + lowest);
  100. }
  101.  
  102. }
  103.  
  104. //NEED HELP WITH WHAT EXAM NUMBER IS HIGHER OR LOWER.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement