Question: Why I recieve following error? COMPILER ERROR MESSAGES RainFall.java:4: error: class rainFall is public, should be declared in a file named rainFall.java public class rainFall

Why I recieve following error?

COMPILER ERROR MESSAGES

RainFall.java:4: error: class rainFall is public, should be declared in a file named rainFall.java public class rainFall {

_________________________________________________

How to add month names January , february etc corresponding to numbers 1-12? In addition HOw to display month name ? for least amont of rain and most amont of rain?

import java.util.Scanner;

public class rainFall {

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 < SIZE; i++) {

do {

System.out.print("Month " + (i + 1) + ": ");

monthlyRain[i] = keyboard.nextDouble();

}

while (monthlyRain[i] < 0);

}

System.out.println("The annual sum of rain: " + sumRain(monthlyRain));

System.out.println("The average sum of rain: " + averageRain(monthlyRain));

System.out.println("The most amount of rain fall: " + mostRain(monthlyRain));

System.out.println("The least amount of rain fall: " + 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 < array.length; i++) {

sum += array[i];

}

return sum;

}

// 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.

static double mostRain(double[] array) {

double most = 0;

for (int i = 0; i < array.length; i++) {

if (array[i] > most) {

most = array[i];

}

}

return most;

}

// Create a function that returns the month with the least rain.

static double leastRain(double[] array) {

double least = array[0];

for (int i = 0; i < array.length; i++) {

if (array[i] < least) {

least = array[i];

}

}

return least;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!