Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.util.Scanner;
- public class RainFall {
- /**
- * @param args the command line arguments
- */
- static double total = 0;
- public static double monthsOfRainfall[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
- public static String monthsNames[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
- public static void main(String[] args) {
- yearlyRainfall();
- averageMonthlyRainfall();
- highestMonth();
- lowestMonth();
- }
- // METHOD TO GATHER THE ALL THE RAINFALL
- public static void yearlyRainfall() {
- Scanner input = new Scanner(System.in);
- for (int i = 0; i < monthsOfRainfall.length; i++) {
- System.out.println("Enter the rainfall for month " + (monthsNames[i]));
- monthsOfRainfall[i] = input.nextDouble();
- if (monthsOfRainfall[i] < 0) {
- i--;
- System.out.println("Error, Invalid Input. Re-Enter integer between 0 and ∞.");
- } else {
- total += monthsOfRainfall[i];
- }
- }
- System.out.println("*********************************");
- System.out.println("The total rainfall for the year is: " + total);
- System.out.println("*********************************");
- }
- //METHOD TO KNOW THE AVERAGE RAIN IN X MONTH
- public static void averageMonthlyRainfall() {
- System.out.println("The average monthly Rainfall is " + total / 12);
- System.out.println("*********************************");
- }
- //METHOD TO KNOW THE HIGHEST RAIN MONTH
- public static void highestMonth() {
- double highest = monthsOfRainfall[0];
- String whatmonth = monthsNames[0];
- int i;
- for (i = 0; i < monthsOfRainfall.length; i++) {
- if (monthsOfRainfall[i] > highest) {
- whatmonth = monthsNames[i];
- highest = monthsOfRainfall[i];
- }
- }
- System.out.println("The Highest month is " + whatmonth + " with a rainfall of: " + highest);
- }
- //METHOD TO KNOW THE LOWWEST RAIN MONTH
- public static void lowestMonth() {
- double lowest = monthsOfRainfall[0];
- String whatmonth = monthsNames[0];
- int i;
- for (i = 0; i < monthsOfRainfall.length; i++) {
- if (monthsOfRainfall[i] < lowest) {
- whatmonth = monthsNames[i];
- lowest = monthsOfRainfall[i];
- }
- }
- System.out.println("*********************************");
- System.out.println("The Lowest month is " + whatmonth + " with a rainfall of: " + lowest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement