Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java homework, can someone help me with this: Use at least two methods in the pr

ID: 3917195 • Letter: J

Question

Java homework, can someone help me with this:

Use at least two methods in the program.
Use an array parameter in a method that uses call by reference when assigning values to the array.


rainfall
Write a program that reads up to 52 double values of weekly rainfall for a given city.
The program then uses a method to input less than 52 values and returns the number entered, with the following header:
public static int getRainData(double rainFall[])
The program uses a method to calculate the average rainfall with the following header:
public static double calcAverage(double rainFall[], int numWeeks)
The output of the program displays all 52 rainfall values followed by the amount above or below the average for each week. Finally, the program displays the smallest and largest rainfall values for the year.

Explanation / Answer

RainfallTest.java

import java.util.Scanner;

public class RainfallTest {

public static void main(String[] args) {

double rainFall[] = new double[52];

int numWeeks = getRainData(rainFall);

double average = calcAverage(rainFall, numWeeks);

System.out.println("Average rain fall is "+average);

double minRainFall = rainFall[0];

double maxRainFall = rainFall[0];

for(int i=0;i<numWeeks;i++) {

if(minRainFall>rainFall[i]) {

minRainFall=rainFall[i];

}

if(maxRainFall<rainFall[i]) {

maxRainFall=rainFall[i];

}

}

System.out.println("Minimum rainfall is "+minRainFall);

System.out.println("Maximum rainfall is "+maxRainFall);

}

public static int getRainData(double rainFall[]) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the input less than 52: ");

int numWeeks = scan.nextInt();

for(int i=0;i<numWeeks;i++) {

System.out.println("Enter the rain fall for the week "+(i+1)+": ");

rainFall[i]=scan.nextDouble();

}

return numWeeks;

}

public static double calcAverage(double rainFall[], int numWeeks) {

double sumRainFall = 0;

for(int i=0;i<numWeeks;i++) {

sumRainFall=sumRainFall+rainFall[i];

}

return sumRainFall/numWeeks;

}

}

Output:

Enter the input less than 52:
10
Enter the rain fall for the week 1:
4.4
Enter the rain fall for the week 2:
3.3
Enter the rain fall for the week 3:
2.2
Enter the rain fall for the week 4:
8.8
Enter the rain fall for the week 5:
9.9
Enter the rain fall for the week 6:
7.7
Enter the rain fall for the week 7:
6.6
Enter the rain fall for the week 8:
5.5
Enter the rain fall for the week 9:
1.1
Enter the rain fall for the week 10:
11.1
Average rain fall is 6.0600000000000005
Minimum rainfall is 1.1
Maximum rainfall is 11.1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote