The Problem Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the number of months above and below the average rainfall, and the highest rainfall for each quarter of the year.
The Assignment Write a Java program that contains five method/functions as follows:
main(). Calls the functions enterRain, rainStats, aboveBelow, and quarterlyRain.
enterRain(). Uses a loop to allow the user to enter rainfall for each of 12 months. Each rainfall should be assigned to an array monthlyRain. monthlyRain should be returned to main() after rainfall for each month has been entered.
rainStats(). Accepts the array monthlyRain. Calculates a total for the year and an average rainfall per month from monthlyRain. Displays the total and average rainfall for the year.
aboveBelow(). Searches the array to count the number of months with above average and below average rainfall. Displays the number of months at or above the average and the number of months below the average rainfall for the year.
quarterlyRain(). Searches the array and finds/displays the highest rainfall for each quarter of the year.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks
// RainFall.java
import java.util.Scanner;
public class RainFall {
static Scanner scanner = new Scanner(System.in);
/**
* method to read the rainfall stats from user and fill the monthlyrain
* array
*
* @return - an array of double containing rainfalls for 12 months
*/
static double[] enterRain() {
double monthlyRain[] = new double[12];
for (int i = 0; i < 12; i++) {
System.out.print("Enter rainfall for month " + (i + 1) + ": ");
monthlyRain[i] = Double.parseDouble(scanner.nextLine());
}
return monthlyRain;
}
/**
* method to display total and average rainfall
*
* @param monthlyRain
* - array containing rainfall info
*/
static void rainStats(double monthlyRain[]) {
double total = 0;
// calculating total
for (int i = 0; i < monthlyRain.length; i++) {
total += monthlyRain[i];
}
System.out.printf("Total rainfall: %.2f\n" ,total);
// finding average (total by count)
double avg = (double) total / monthlyRain.length;
System.out.printf("Average rainfall: %.2f\n" , avg);
}
/**
* method to display number of months above and below average rainfall
*
* @param monthlyRain
* - array containing rainfall info
*/
static void aboveBelow(double monthlyRain[]) {
// finding average first
double total = 0;
for (int i = 0; i < monthlyRain.length; i++) {
total += monthlyRain[i];
}
double avg = (double) total / monthlyRain.length;
/***
* initializing variables to keep the track of number of months above
* and below average
*/
int above = 0;
int below = 0;
// looping through the array and incrementing the appropriate counter
for (int i = 0; i < monthlyRain.length; i++) {
if (monthlyRain[i] >= avg) {
above++;
} else {
below++;
}
}
System.out.println("There are " + above
+ " months with rainfall above average, and " + below
+ " months with rainfall below average");
}
/**
* method to display highest rainfall in each quarter
*
* @param monthlyRain
* - array containing rainfall info
*/
static void quarterlyRain(double monthlyRain[]) {
int monthsIndex = 0;
int quarter = 1;
/**
* looping for 4 times (4 quarters)
*/
while (quarter <= 4) {
/**
* finding the highest in this quarter
*/
double highest = 0;
for (int i = monthsIndex; i < monthsIndex + 3; i++) {
if (i == monthsIndex) {
// first month in the quarter
highest = monthlyRain[i];
} else if (monthlyRain[i] > highest) {
highest = monthlyRain[i];
}
}
/**
* displaying the highest rainfall for this quarter
*/
System.out.println("Highest rainfall for quarter " + quarter
+ " is: " + highest);
// moving to next quarter
monthsIndex += 3;
quarter++;
}
}
public static void main(String[] args) {
// getting input
double monthlyRain[] = enterRain();
// printing total and avg
rainStats(monthlyRain);
// finding number of months above and below avg
aboveBelow(monthlyRain);
// printing quarterly highest rainfalls info
quarterlyRain(monthlyRain);
}
}
/*OUTPUT*/
Enter rainfall for month 1: 44.5
Enter rainfall for month 2: 23.6
Enter rainfall for month 3: 11.5
Enter rainfall for month 4: 30.5
Enter rainfall for month 5: 78.5
Enter rainfall for month 6: 88.1
Enter rainfall for month 7: 45.2
Enter rainfall for month 8: 30.2
Enter rainfall for month 9: 25.1
Enter rainfall for month 10: 10.7
Enter rainfall for month 11: 3.6
Enter rainfall for month 12: 5.6
Total rainfall: 397.10
Average rainfall: 33.10
There are 4 months with rainfall above average, and 8 months with rainfall below average
Highest rainfall for quarter 1 is: 44.5
Highest rainfall for quarter 2 is: 88.1
Highest rainfall for quarter 3 is: 45.2
Highest rainfall for quarter 4 is: 10.7
The Problem Design a program that lets the user enter the total rainfall for each of...
Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amount. PLEASE MODULARIZED THE CODE PLEASE USE C PROGRAMMING AND ADD PSEUDOCODE
Write a program in C++ that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Input validation: Do not accept negative numbers for monthly rainfall figures.
Rainfall Statistics Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November, December....
Write a Python program that allows the user to enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January: 8.9 inches February: 11.1 inches March: 13.4 inches April: 6.9 inches May: 8.7 inches June: 9.1 inches July: 15.9 inches August: 4.4 inches September: 3.1 inches October: 5.6 inches November: 7.8...
pseudocode and Python Repl.it :Recall that Programming Exercise 3 in Chapter 8 asked you to design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Enhance the program so it sorts the array in ascending order and displays the values it contains.
Write a program that scores the total rainfall for each of 12 months into an array double. A sample array definition is shown below double thisYear[] = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3, 2.4, 3.7}; The program should have the four functions to calculate the following 1. The total rainfall for the year 2. The average monthly rainfall 3. The month with most rain 4. The month with least rain Output: What to deliver? Your .cpp...
Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations,...
Write a C++ console application that allows your user to capture rainfall statistics. Your program should contain an array of 12 doubles for the rainfall values as well as a parallel array containing the names of the months. Using each of the month names, prompt your user for the total rainfall for that month. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should...
Program 2 <100 points>: Chips and Salsa (chipsSalsa.cpp) Write a program that lets a maker of chips and salsa keep track of sales for five different types of salsa: mild, medium, sweet, hot, and zesty. The program should use two parallel 5-element arrays: an array of strings that holds the five salsa names and an array of integers that holds the number of jars sold during the past month for each salsa type. The salsa names should be stored using...
Rainfall StatisticsWrite a modular program that analyzes a year's worth of rainfall data. In addition to main, the program should have a getData function that accepts the total rainfallfor each of 12 months from the user, and stores it in a double array. It should also have four value-returning functions that compute and return to main thetotalRainfall, averageRainfall, driestRainfall, and wettestMonth. These last two functions return the number of the month with the lowest and highest rainfall amounts,not the amount...