Advertisement
Ccuevas3410

Untitled

Sep 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 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. // METHOD TO GATHER THE ALL THE RAINFALL
  28.  
  29. public static void yearlyRainfall() {
  30.  
  31. Scanner input = new Scanner(System.in);
  32.  
  33. for (int i = 0; i < monthsOfRainfall.length; i++) {
  34.  
  35. System.out.println("Enter the rainfall for month " + (monthsNames[i]));
  36.  
  37. monthsOfRainfall[i] = input.nextDouble();
  38.  
  39. if (monthsOfRainfall[i] < 0) {
  40. i--;
  41. System.out.println("Error, Invalid Input. Re-Enter integer between 0 and ∞.");
  42. } else {
  43.  
  44. total += monthsOfRainfall[i];
  45. }
  46.  
  47. }
  48. System.out.println("*********************************");
  49. System.out.println("The total rainfall for the year is: " + total);
  50.  
  51. System.out.println("*********************************");
  52.  
  53. }
  54. //METHOD TO KNOW THE AVERAGE RAIN IN X MONTH
  55.  
  56. public static void averageMonthlyRainfall() {
  57.  
  58. System.out.println("The average monthly Rainfall is " + total / 12);
  59. System.out.println("*********************************");
  60.  
  61. }
  62. //METHOD TO KNOW THE HIGHEST RAIN MONTH
  63.  
  64. public static void highestMonth() {
  65.  
  66. double highest = monthsOfRainfall[0];
  67.  
  68. String whatmonth = monthsNames[0];
  69. int i;
  70.  
  71. for (i = 0; i < monthsOfRainfall.length; i++) {
  72.  
  73. if (monthsOfRainfall[i] > highest) {
  74. whatmonth = monthsNames[i];
  75. highest = monthsOfRainfall[i];
  76.  
  77. }
  78.  
  79. }
  80. System.out.println("The Highest month is " + whatmonth + " with a rainfall of: " + highest);
  81. }
  82.  
  83. //METHOD TO KNOW THE LOWWEST RAIN MONTH
  84. public static void lowestMonth() {
  85.  
  86. double lowest = monthsOfRainfall[0];
  87. String whatmonth = monthsNames[0];
  88. int i;
  89.  
  90. for (i = 0; i < monthsOfRainfall.length; i++) {
  91.  
  92. if (monthsOfRainfall[i] < lowest) {
  93. whatmonth = monthsNames[i];
  94. lowest = monthsOfRainfall[i];
  95. }
  96.  
  97. }
  98.  
  99. System.out.println("*********************************");
  100. System.out.println("The Lowest month is " + whatmonth + " with a rainfall of: " + lowest);
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement