Use at least two methods in the program. Use an array parameter in a method that
ID: 3860041 • Letter: U
Question
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. Turn in the program listing and sample program output(s) Choose one of the following: 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. Write a program that grades the multiple choice drivers' license exam. The exam has the following answer key: 1. B 2.D 3.A 4. A 5.C 6.A 7.B 8.A 9.C 10. D 11. B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19. D 20. A The program will input a person's answers and display the percent correct along with a message whether they passed or failed the test. Use the following methods: public static void getExamData (char responses[]) that will let the user input the 20 values public static boolean passed (int numCorrect) that returns true if they answer at least 15 out of the 20 correctly. public static int totalCorrect (char responses []) returns the number of correct answers using an array containing the answer keyExplanation / Answer
Question 1
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:
5
Enter the rain fall for the week 1:
11
Enter the rain fall for the week 2:
44
Enter the rain fall for the week 3:
33
Enter the rain fall for the week 4:
55
Enter the rain fall for the week 5:
22
Average rain fall is 33.0
Minimum rainfall is 11.0
Maximum rainfall is 55.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.