Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA, need help to match the expected result My code: import java.util.Scanner; public class RainFall { // string array to store the months names starting

JAVA, need help to match the expected result

image text in transcribed

My code:

import java.util.Scanner;

public class RainFall {

// string array to store the months names starting with index 0 to 11 private static final String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

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

final int SIZE = 12; double[] monthlyRain = new double[SIZE];

System.out.println("Enter the monthly rain fall amount: "); int i = 0;

// Added input validation with 'Do-While Loop' for (i = 0; i

do { System.out.print("Enter rainfall for month " + (i + 1) + ": "); monthlyRain[i] = keyboard.nextDouble(); } while (monthlyRain[i]

}

System.out.println("The annual sum of rain: " + sumRain(monthlyRain)); System.out.println("The average sum of rain: " + averageRain(monthlyRain)); System.out.println("Month with most amount of rain fall: " + months[mostRain(monthlyRain)]); System.out.println("Month with least amount of rain fall: " + months[leastRain(monthlyRain)]); }

// Create a function that returns the total rainFall for the year.

static double sumRain(double[] array) { double sum = 0; for (int i = 0; i

// Create a function that returns the average monthly rainFall for the year. static double averageRain(double[] array) { double average = 0; average = sumRain(array) / array.length; return average; }

// Create a function that returns the month with the most rain. // function modified to return the month index static int mostRain(double[] array) { double most = array[0]; int mostMonthIndex=0; for (int i = 0; i most) { most = array[i]; mostMonthIndex=i; } } return mostMonthIndex; }

// Create a function that returns the month with the least rain. // function modified to return the month index static int leastRain(double[] array) { double least = array[0]; int leastMonthIndex=0; for (int i = 0; i

}

12.12 1.48J 3.12 3.24 6.6 1.12 you displayed: Enter the monthly.rain-fall-amount: Enter rainfall-for-month-1: Enter rainfall-for-month-2: Enter rainfall-for-month-3:Enterrainfall-for-month-4:-Enter-rainfall-for-month-5 The average sum-of-rain:-3.49 Month-with-most-amount-of-rain-fall:-July Month-with-least amount-of-rain-fall:-April- instead of: Enter rainfall-for-month-1: Enter-rainfall-for-month-2: Enter-rainfall-for-month-3: Enter rainfall-for-month-4:Enter-rainfall-for-month-5:E 3.49 July April Failed 3 out of 3 test runs. Failed Test Run #1 The contents of your standard output is incorrect. There is an error in your prompts. Standard Output - W Hide Invisibles) Expected Result: Enter rainfall for 'month.1: Enter rainfall for month.1: Enter rainfall. 5.065 May October Your Code's Actual Result: Enter the monthly rain fall amount: Enter rainfall for month:1:Enter rainfall for month.1: Enter rainfall The average sum of rain: -5.0654 Month with most amount of rain fall: May Month with least amount of rain fall: October

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

Th e last time I complained, nothing happened.

Answered: 1 week ago

Question

7. What traps should she avoid?

Answered: 1 week ago

Question

5. What decision-making model would you advocate to this person?

Answered: 1 week ago

Question

6. What data will she need?

Answered: 1 week ago