Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

________________________

This is my current code:

import java.util.Scanner; public class Rainfall { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); final int SIZE =12; double[] rainfall = new double[SIZE]; for (int i = 0; i < SIZE; i++) { System.out.printf("Enter the rainfall amount for month %d: ", i + 1); rainfall[i] = keyboard.nextDouble(); } System.out.printf("Maximum rainfall: %.1f ", findMax(rainfall)); System.out.printf("Minimum rainfall: %.1f ", findMin(rainfall)); System.out.printf("Total rainfall: %.1f ", findSum(rainfall)); System.out.printf("Average rainfall: %.1f ", findAvg(rainfall)); keyboard.close(); } public static double findMax(double[] array) { double max = array[0]; for (int i = 1; i < array.length; i++) { if (array[i] > max) max = array[i]; } return max; } public static double findMin(double[] array) { double min = array[0]; for (int i = 0; i < array.length; i++) { if (array[i] < min) min = array[i]; } return min; } public static double findSum(double[] array) { double total = 0; for(double element : array) total +=element; return total; } public static double findAvg(double[] array) { return findSum(array) / array.length; } } 

________________________________________________________

Current Input my code gives:

Enter the rainfall amount for month 1: Enter the rainfall amount for month 2: Enter the rainfall amount for month 3: Enter the rainfall amount for month 4: Enter the rainfall amount for month 5: Enter the rainfall amount for month 6: Enter the rainfall amount for month 7: Enter the rainfall amount for month 8: Enter the rainfall amount for month 9: Enter the rainfall amount for month 10: Enter the rainfall amount for month 11: Enter the rainfall amount for month 12: Maximum rainfall: 6.6 Minimum rainfall: 1.1 Total rainfall: 45.2 Average rainfall: 3.8 

I need the input to be like this.

Enter the rainfall amount for month 1: Enter the rainfall amount for month 2: Enter the rainfall amount for month 3: Enter the rainfall amount for month 4: Enter the rainfall amount for month 5: Enter the rainfall amount for month 6: Enter the rainfall amount for month 7: Enter the rainfall amount for month 8: Enter the rainfall amount for month 9: Enter the rainfall amount for month 10: Enter the rainfall amount for month 11: Enter the rainfall amount for month 12: Maximum rainfall: February, 6.7 inches Minimum rainfall: October, 1.2 inches Total rainfall: 45.8 inches Average rainfall: 3.8 inches 

Please help!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions