Write a RainFall class that stores the total rainfall for each of 12 months into an array of

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
Your Question:
Chapter 7. PC #1. Rainfall Class
Write a RainFall class that stores the total rainfall for each of 12 months into an array of
doubles. The program should have methods that return the following:
• the total rainfall for the year
• the average monthly rainfall
• the month with the most rain
• the month with the least rain
Demonstrate the class in a complete program.
Main class name: RainFall (no package name)
 
PLEASE MODIFY THIS CODE SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES THE TEST CASES. IT HAS TO PASS THE TEST CASES BECAUSE WHEN I UPLOAD IT TO HYPERGRADE IT DOES NOT PASS THE TEST CASES. I HAVE PROVIDED PROOF OF THE PART OF THE TEST CASE THAT FAILED. 
 

import java.util.Scanner;

public class Rainfall {
    double rain[];

    public Rainfall() {
        rain = new double[12];
    }

    public double averageRainfall() {
        double number = getTotalRain() / 12.0;
        double roundedNumber = Math.round(number * 10.0) / 10.0;
        return roundedNumber;
    }

    public double getTotalRain() {
        double total = 0.0;
        for (int i = 0; i < 12; i++)
            total += rain[i];

        return total;
    }

    public int lowRainMonth() {
        double min = rain[0];
        int month = 0;
        for (int i = 1; i < 12; i++) {
            if (rain[i] < min) {
                min = rain[i];
                month = i;
            }
        }

        return month;
    }

    public int highRainMonth() {
        double max = rain[0];
        int month = 0;
        for (int i = 1; i < 12; i++) {
            if (rain[i] > max) {
                max = rain[i];
                month = i;
            }
        }

        return month;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Rainfall obj = new Rainfall();

        for (int i = 0; i < 12; i++) {
            System.out.println("Enter the rainfall amount for month " + (i + 1) + ":");
            obj.rain[i] = sc.nextDouble();
        }

        System.out.println("Maximum rainfall: " + obj.rain[obj.highRainMonth()]);
        System.out.println("Minimum rainfall: " + obj.rain[obj.lowRainMonth()]);
        System.out.println("Total rainfall:  " + obj.getTotalRain());
        System.out.println("Average rainfall:  " + obj.averageRainfall());
    }
}

 

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: 6.6\n
Minimum rainfall: 1.1\n
Total rainfall: 45.2\n
Average rainfall: 3.8\n
 
 
 
 
 
Enter the rainfall amount for month 1: \n
1.2 ENTER
Enter the rainfall amount for month 2: \n
2.3 ENTER
Enter the rainfall amount for month 3: \n
3.4 ENTER
Enter the rainfall amount for month 4: \n
5.1 ENTER
Enter the rainfall amount for month 5: \n
1.7 ENTER
Enter the rainfall amount for month 6: \n
6.5 ENTER
Enter the rainfall amount for month 7: \n
2.5 ENTER
Enter the rainfall amount for month 8: \n
3.3 ENTER
Enter the rainfall amount for month 9: \n
1.1 ENTER
Enter the rainfall amount for month 10: \n
5.5 ENTER
Enter
6.6 ENTER
Enter the rainfall amount for month 12: \n
6.0 ENTER
rainfall amount for month 11: \n
Maximum rainfall: 6.6\n
Minimum rainfall: 1.1\n
Total rainfall: 45.2\n
Average rainfall: 3.8\n
Transcribed Image Text:Enter the rainfall amount for month 1: \n 1.2 ENTER Enter the rainfall amount for month 2: \n 2.3 ENTER Enter the rainfall amount for month 3: \n 3.4 ENTER Enter the rainfall amount for month 4: \n 5.1 ENTER Enter the rainfall amount for month 5: \n 1.7 ENTER Enter the rainfall amount for month 6: \n 6.5 ENTER Enter the rainfall amount for month 7: \n 2.5 ENTER Enter the rainfall amount for month 8: \n 3.3 ENTER Enter the rainfall amount for month 9: \n 1.1 ENTER Enter the rainfall amount for month 10: \n 5.5 ENTER Enter 6.6 ENTER Enter the rainfall amount for month 12: \n 6.0 ENTER rainfall amount for month 11: \n Maximum rainfall: 6.6\n Minimum rainfall: 1.1\n Total rainfall: 45.2\n Average rainfall: 3.8\n
Expert Solution
Step 1: Outline of the given question

In the given question, you are asked to create a Java class called `Rainfall` that can store monthly rainfall data for a year and perform the following tasks:

1. Calculate the total rainfall for the year.
2. Calculate the average monthly rainfall.
3. Identify the month with the highest amount of rainfall.
4. Identify the month with the lowest amount of rainfall.

You are also required to demonstrate the functionality of this class in a complete Java program.

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Array
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