Introduction In this lab, we will look at various aspects of methods in Java programming such as...

70.2K

Verified Solution

Question

Programming

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:

  1. the total rainfall per year
  2. the average monthly rainfall (for twoyears)
  3. 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:
  1. year should greater than 1990.
  2. 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 :

  1. Display the year that received themost rain.

Answer & Explanation Solved by verified expert
3.8 Ratings (514 Votes)
Here is the answer for your questionin Java Programming LanguageKindly upvote if you findthe answer helpfulNOTE I have given code forboth Excercise 1 and Excercise 2 Please comment if you have    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students