Introduction
In this lab, we will look at various aspects of methods in Javaprogramming such as passing arguments to a method, use of localvariables, and returning a value from a method.
Exercise-1: RainFall Statistisc(50 pts)
Write a program that asks user the total rainfall forthe last six months of two consecutive years and do thefollowing:
- the total rainfall per year
- the average monthly rainfall (for twoyears)
- the month with the most rain (per year)
You need to break your code into the following methods:
- run: It asks the user to enter the year andrainfall values for each month (last six months) and reads theinput as a double from the keyboard. It callsisValid method for validity check of the year. IfisValid method returns true, then program will askfor the rainfall values from July to December for that year. Eachtime user will enter the rainfall values; isValidmethod will be called to check for the validity of the input. Once,the user enters all the required input, and then the method willshow the output in the format as shown above.
- isValid: It returns true in the followingscenario:
- year should greater than 1990.
- The monthly rainfall cannot be negative
Otherwise, it returns false.
Exercise 2: (30 pts)
Add a code segment to the code that you complète inExercise1 to do the following :
- Display the year that received themost rain.