JAVA PROGRAM Lab #1 Enhancements:1. For the maximum and minimum rainfall amount, also display the month where that happened. For example:a. Maximum rainfall: January, 88.2 inchesb. Minimum rainfall: July, 12.3 inches2. Format all numbers with 1 decimal pointsMain class name: RainFall2 (no package name) HERE IS A WORKING CODE, PLEASE MODIFY THIS CODE SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL THE TEST CASSES. IT HAS TO PASS ALL THE TEST CASSES BECAUSE RIGHT KNOW IT DOES NOT PASS THE TEST CASES. THANK YOU import java.util.*; public class Main {     public static void main(String[] args) {         String maxRainfallMonth = "",minRainfallMonth = "";         double maxRainfall,minRainfall,rainFall,avg,tot=0;         Scanner sc = new Scanner(System.in);         System.out.println("Enter the rainfall for month 1: ");         double rainfall = sc.nextDouble();         maxRainfall = rainfall;         minRainfall = rainfall;         tot = rainfall;         String[] months = {"January","February","March","April",             "May","June","July","August","September","October",             "November","Decemeber",};         maxRainfallMonth = months[0];         minRainfallMonth = months[0];        for(int i=1; irainfall){             minRainfall = rainfall;             minRainfallMonth = months[i];         }         if(maxRainfall

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

JAVA PROGRAM

Lab #1 Enhancements:1. For the maximum and minimum rainfall amount, also display the month where that happened. For example:a. Maximum rainfall: January, 88.2 inchesb. Minimum rainfall: July, 12.3 inches2. Format all numbers with 1 decimal pointsMain class name: RainFall2 (no package name)

HERE IS A WORKING CODE, PLEASE MODIFY THIS CODE SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL THE TEST CASSES. IT HAS TO PASS ALL THE TEST CASSES BECAUSE RIGHT KNOW IT DOES NOT PASS THE TEST CASES. THANK YOU

import java.util.*;
public class Main
{
    public static void main(String[] args) {
        String maxRainfallMonth = "",minRainfallMonth = "";
        double maxRainfall,minRainfall,rainFall,avg,tot=0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the rainfall for month 1: ");
        double rainfall = sc.nextDouble();
        maxRainfall = rainfall;
        minRainfall = rainfall;
        tot = rainfall;
        String[] months = {"January","February","March","April",
            "May","June","July","August","September","October",
            "November","Decemeber",};
        maxRainfallMonth = months[0];
        minRainfallMonth = months[0];
       for(int i=1; i<months.length; i++){
       System.out.println("Enter the rainfall for month "+(i+1)+": ");
        rainfall = sc.nextDouble();
        if(minRainfall>rainfall){
            minRainfall = rainfall;
            minRainfallMonth = months[i];
        }
        if(maxRainfall<rainfall){
            maxRainfall = rainfall;
            maxRainfallMonth = months[i];
        }
        tot += rainfall;
       }
    avg = tot/12;
    System.out.printf("Maximum rainfall: %s, %.1f inches\n",maxRainfallMonth,maxRainfall);
    System.out.printf("Minimum rainfall: %s, %.1f inches\n",minRainfallMonth,minRainfall);
    System.out.printf("Total rainfall:%.1f inches\n",tot);
    System.out.printf("Average rainfall:%.1f inches\n",avg);
    }
}

 

Test Case 1

 
 
Enter the rainfall amount for month 1:\n
1.2ENTER
Enter the rainfall amount for month 2:\n
2.3ENTER
Enter the rainfall amount for month 3:\n
3.4ENTER
Enter the rainfall amount for month 4:\n
5.1ENTER
Enter the rainfall amount for month 5:\n
1.7ENTER
Enter the rainfall amount for month 6:\n
6.5ENTER
Enter the rainfall amount for month 7:\n
2.5ENTER
Enter the rainfall amount for month 8:\n
3.3ENTER
Enter the rainfall amount for month 9:\n
1.1ENTER
Enter the rainfall amount for month 10:\n
5.5ENTER
Enter the rainfall amount for month 11:\n
6.6ENTER
Enter the rainfall amount for month 12:\n
6.0ENTER
Maximum rainfall: November, 6.6 inches\n
Minimum rainfall: September, 1.1 inches\n
Total rainfall: 45.2 inches\n
Average rainfall: 3.8 inches\n
 

Test Case 2

 
 
Enter the rainfall amount for month 1:\n
1.29ENTER
Enter the rainfall amount for month 2:\n
6.68ENTER
Enter the rainfall amount for month 3:\n
2.37ENTER
Enter the rainfall amount for month 4:\n
3.46ENTER
Enter the rainfall amount for month 5:\n
5.15ENTER
Enter the rainfall amount for month 6:\n
1.74ENTER
Enter the rainfall amount for month 7:\n
6.53ENTER
Enter the rainfall amount for month 8:\n
2.52ENTER
Enter the rainfall amount for month 9:\n
3.31ENTER
Enter the rainfall amount for month 10:\n
1.17ENTER
Enter the rainfall amount for month 11:\n
5.53ENTER
Enter the rainfall amount for month 12:\n
6.01ENTER
Maximum rainfall: February, 6.7 inches\n
Minimum rainfall: October, 1.2 inches\n
Total rainfall: 45.8 inches\n
Average rainfall: 3.8 inches\n
 
 

 

Expert Solution
Step 1: Algorithm:

1. Initialize variables maxRainfallMonth and minRainfallMonth to store the names of the months with the maximum and minimum rainfall.

2. Initialize variables maxRainfall and minRainfall to store the maximum and minimum rainfall values, respectively. Set maxRainfall to 0.0 and minRainfall to the maximum possible double value.

3. Initialize variables rainFall, avg, and tot to 0.

4. Create a Scanner object sc to read user input.

5. Create an array months containing the names of the twelve months.

6. Iterate over each month using a loop from 0 to 11 (representing the twelve months).
       a. Prompt the user to input the rainfall amount for the current month.
       b. Read and store the input in the variable rainfall.
       c. Check if this is the first iteration (i.e., i == 0):

    • If true, set maxRainfall and minRainfall to the current rainfall value.
    • Set maxRainfallMonth and minRainfallMonth to the name of the current month.

         d. If it's not the first iteration:

    • Compare the current rainfall value with minRainfall and update minRainfall and minRainfallMonth if the current value is smaller.
    • Compare the current rainfall value with maxRainfall and update maxRainfall and maxRainfallMonth if the current value is larger.

         e. Add the current rainfall value to the total tot.
7. Calculate the average rainfall avg by dividing the total tot by the number of months (12).
8. Print the following information:
     a. The maximum rainfall month and value: "Maximum rainfall: [maxRainfallMonth], [maxRainfall] inches"
     b. The minimum rainfall month and value: "Minimum rainfall: [minRainfallMonth], [minRainfall] inches"
     c. The total rainfall: "Total rainfall: [tot] inches"
     d. The average rainfall: "Average rainfall: [avg] inches"

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education