SlideShare a Scribd company logo
1 of 6
Download to read offline
Hi Please find my code:
####### RainFall.java ###################
public class RainFall {
private double[] monthlyRainFallArr;
public RainFall(double[] rainFallArr) {
monthlyRainFallArr = new double[12]; // creating an array to store monthly rainfall
for(int i=0; i<12; i++)
monthlyRainFallArr[i] = rainFallArr[i];
}
public double getTotalRainFallForYear(){
double total = 0;
for(int i=0; i<12; i++)
total += monthlyRainFallArr[i];
return total;
}
// function to get average monthly rail fall
public double getAverageMonthlyRainFall(){
double totalYear = getTotalRainFallForYear();
return totalYear/12;
}
// function to get month number with least rail fall
public int getMonthWithLeastRainFall(){
int min_index = 0;
for(int i=1; i<12; i++){
if(monthlyRainFallArr[i] < monthlyRainFallArr[min_index]){
min_index = i;
}
}
return (min_index+1);
}
// function to get month number with most rail fall
public int getMonthWithMostRainFall(){
int max_index = 0;
for(int i=1; i<12; i++){
if(monthlyRainFallArr[i] > monthlyRainFallArr[max_index]){
max_index = i;
}
}
return (max_index+1);
}
}
############## RainFallTest.java ##################
import java.util.Scanner;
public class RainFallTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double rainFallArr[] = new double[12];
System.out.println("Enter rain fall data for 12 month: ");
for(int i=0; i<12; i++){
System.out.print("Rail Fall data for "+(i+1)+" month: ");
rainFallArr[i] = sc.nextDouble();
}
RainFall rainfall = new RainFall(rainFallArr);
System.out.println("Total rain fall for year: "+rainfall.getTotalRainFallForYear());
System.out.println("Average monthly rain fall: "+rainfall.getAverageMonthlyRainFall());
System.out.println("Month Number with least rainfall:
"+rainfall.getMonthWithLeastRainFall());
System.out.println("Month Number with most rainfall:
"+rainfall.getMonthWithMostRainFall());
}
}
/*
Sample Output:
Enter rain fall data for 12 month:
Rail Fall data for 1 month: 45.43
Rail Fall data for 2 month: 48.76
Rail Fall data for 3 month: 46.56
Rail Fall data for 4 month: 47.23
Rail Fall data for 5 month: 44.32
Rail Fall data for 6 month: 43.23
Rail Fall data for 7 month: 58.76
Rail Fall data for 8 month: 55.65
Rail Fall data for 9 month: 50.76
Rail Fall data for 10 month: 49.12
Rail Fall data for 11 month: 37.45
Rail Fall data for 12 month: 38.00
Total rain fall for year: 565.27
Average monthly rain fall: 47.10583333333333
Month Number with least rainfall: 11
Month Number with most rainfall: 7
*/
Solution
Hi Please find my code:
####### RainFall.java ###################
public class RainFall {
private double[] monthlyRainFallArr;
public RainFall(double[] rainFallArr) {
monthlyRainFallArr = new double[12]; // creating an array to store monthly rainfall
for(int i=0; i<12; i++)
monthlyRainFallArr[i] = rainFallArr[i];
}
public double getTotalRainFallForYear(){
double total = 0;
for(int i=0; i<12; i++)
total += monthlyRainFallArr[i];
return total;
}
// function to get average monthly rail fall
public double getAverageMonthlyRainFall(){
double totalYear = getTotalRainFallForYear();
return totalYear/12;
}
// function to get month number with least rail fall
public int getMonthWithLeastRainFall(){
int min_index = 0;
for(int i=1; i<12; i++){
if(monthlyRainFallArr[i] < monthlyRainFallArr[min_index]){
min_index = i;
}
}
return (min_index+1);
}
// function to get month number with most rail fall
public int getMonthWithMostRainFall(){
int max_index = 0;
for(int i=1; i<12; i++){
if(monthlyRainFallArr[i] > monthlyRainFallArr[max_index]){
max_index = i;
}
}
return (max_index+1);
}
}
############## RainFallTest.java ##################
import java.util.Scanner;
public class RainFallTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double rainFallArr[] = new double[12];
System.out.println("Enter rain fall data for 12 month: ");
for(int i=0; i<12; i++){
System.out.print("Rail Fall data for "+(i+1)+" month: ");
rainFallArr[i] = sc.nextDouble();
}
RainFall rainfall = new RainFall(rainFallArr);
System.out.println("Total rain fall for year: "+rainfall.getTotalRainFallForYear());
System.out.println("Average monthly rain fall: "+rainfall.getAverageMonthlyRainFall());
System.out.println("Month Number with least rainfall:
"+rainfall.getMonthWithLeastRainFall());
System.out.println("Month Number with most rainfall:
"+rainfall.getMonthWithMostRainFall());
}
}
/*
Sample Output:
Enter rain fall data for 12 month:
Rail Fall data for 1 month: 45.43
Rail Fall data for 2 month: 48.76
Rail Fall data for 3 month: 46.56
Rail Fall data for 4 month: 47.23
Rail Fall data for 5 month: 44.32
Rail Fall data for 6 month: 43.23
Rail Fall data for 7 month: 58.76
Rail Fall data for 8 month: 55.65
Rail Fall data for 9 month: 50.76
Rail Fall data for 10 month: 49.12
Rail Fall data for 11 month: 37.45
Rail Fall data for 12 month: 38.00
Total rain fall for year: 565.27
Average monthly rain fall: 47.10583333333333
Month Number with least rainfall: 11
Month Number with most rainfall: 7
*/

More Related Content

Similar to Hi Please find my code####### RainFall.java ###################.pdf

tested on EclipseRainfall.javaimpo.pdf
tested on EclipseRainfall.javaimpo.pdftested on EclipseRainfall.javaimpo.pdf
tested on EclipseRainfall.javaimpo.pdf
sutharbharat59
 
Rewrite lab assignment 7 using pointer to allocate the array memory..pdf
Rewrite lab assignment 7 using pointer to allocate the array memory..pdfRewrite lab assignment 7 using pointer to allocate the array memory..pdf
Rewrite lab assignment 7 using pointer to allocate the array memory..pdf
callawaycorb73779
 
tested on eclipseRainFall.javai.pdf
tested on eclipseRainFall.javai.pdftested on eclipseRainFall.javai.pdf
tested on eclipseRainFall.javai.pdf
arasequ
 
C# Programming. Using methods to call results to display. The code i.pdf
C# Programming. Using methods to call results to display. The code i.pdfC# Programming. Using methods to call results to display. The code i.pdf
C# Programming. Using methods to call results to display. The code i.pdf
fatoryoutlets
 

Similar to Hi Please find my code####### RainFall.java ###################.pdf (20)

4.Spring IoC&DI(Spring Ioc실습_어노테이션 기반)
4.Spring IoC&DI(Spring Ioc실습_어노테이션 기반)4.Spring IoC&DI(Spring Ioc실습_어노테이션 기반)
4.Spring IoC&DI(Spring Ioc실습_어노테이션 기반)
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
tested on EclipseRainfall.javaimpo.pdf
tested on EclipseRainfall.javaimpo.pdftested on EclipseRainfall.javaimpo.pdf
tested on EclipseRainfall.javaimpo.pdf
 
Don't Make Android Bad... Again
Don't Make Android Bad... AgainDon't Make Android Bad... Again
Don't Make Android Bad... Again
 
How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
 
AngularJS $Provide Service
AngularJS $Provide ServiceAngularJS $Provide Service
AngularJS $Provide Service
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Microservices Architecture: Labs
Microservices Architecture: LabsMicroservices Architecture: Labs
Microservices Architecture: Labs
 
Rewrite lab assignment 7 using pointer to allocate the array memory..pdf
Rewrite lab assignment 7 using pointer to allocate the array memory..pdfRewrite lab assignment 7 using pointer to allocate the array memory..pdf
Rewrite lab assignment 7 using pointer to allocate the array memory..pdf
 
Event Sourcing with php
Event Sourcing with phpEvent Sourcing with php
Event Sourcing with php
 
tested on eclipseRainFall.javai.pdf
tested on eclipseRainFall.javai.pdftested on eclipseRainFall.javai.pdf
tested on eclipseRainFall.javai.pdf
 
C# Programming. Using methods to call results to display. The code i.pdf
C# Programming. Using methods to call results to display. The code i.pdfC# Programming. Using methods to call results to display. The code i.pdf
C# Programming. Using methods to call results to display. The code i.pdf
 
A resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleA resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangle
 
Building maintainable app #droidconzg
Building maintainable app #droidconzgBuilding maintainable app #droidconzg
Building maintainable app #droidconzg
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
F# in the enterprise
F# in the enterpriseF# in the enterprise
F# in the enterprise
 
Building maintainable app
Building maintainable appBuilding maintainable app
Building maintainable app
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 

More from APMRETAIL

#include iostream #include string #include invalidHr.h.pdf
 #include iostream #include string #include invalidHr.h.pdf #include iostream #include string #include invalidHr.h.pdf
#include iostream #include string #include invalidHr.h.pdf
APMRETAIL
 
The start of the European Colonization is typically dated to 1492, a.pdf
The start of the European Colonization is typically dated to 1492, a.pdfThe start of the European Colonization is typically dated to 1492, a.pdf
The start of the European Colonization is typically dated to 1492, a.pdf
APMRETAIL
 
Sewage before being disposed of either in river stream or on land, h.pdf
Sewage before being disposed of either in river stream or on land, h.pdfSewage before being disposed of either in river stream or on land, h.pdf
Sewage before being disposed of either in river stream or on land, h.pdf
APMRETAIL
 
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdf
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdfRelational database was proposed by Edgar Codd (of IBM Research) aro.pdf
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdf
APMRETAIL
 
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdfI hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
APMRETAIL
 

More from APMRETAIL (20)

The Periodic table of elements are classified through color dependi.pdf
 The Periodic table of elements are classified through color dependi.pdf The Periodic table of elements are classified through color dependi.pdf
The Periodic table of elements are classified through color dependi.pdf
 
#include iostream #include string #include invalidHr.h.pdf
 #include iostream #include string #include invalidHr.h.pdf #include iostream #include string #include invalidHr.h.pdf
#include iostream #include string #include invalidHr.h.pdf
 
option D) answer A and B are both correct .pdf
                     option   D) answer A and B are both correct      .pdf                     option   D) answer A and B are both correct      .pdf
option D) answer A and B are both correct .pdf
 
image not visible clearly. please give points to .pdf
                     image not visible clearly. please give points to .pdf                     image not visible clearly. please give points to .pdf
image not visible clearly. please give points to .pdf
 
HI(g) has the highest molar entropy as it has h.pdf
                     HI(g)  has the highest molar entropy  as it has h.pdf                     HI(g)  has the highest molar entropy  as it has h.pdf
HI(g) has the highest molar entropy as it has h.pdf
 
ion-dipole Solution ion-.pdf
                     ion-dipole  Solution                     ion-.pdf                     ion-dipole  Solution                     ion-.pdf
ion-dipole Solution ion-.pdf
 
Yes. It has SP2 hybridisation , with 2 lone pairs.pdf
                     Yes. It has SP2 hybridisation , with 2 lone pairs.pdf                     Yes. It has SP2 hybridisation , with 2 lone pairs.pdf
Yes. It has SP2 hybridisation , with 2 lone pairs.pdf
 
Using, M1V1 = M2V2 10.0 x 0.1106 = M2 x 13.64 M.pdf
                     Using, M1V1 = M2V2  10.0 x 0.1106 = M2 x 13.64  M.pdf                     Using, M1V1 = M2V2  10.0 x 0.1106 = M2 x 13.64  M.pdf
Using, M1V1 = M2V2 10.0 x 0.1106 = M2 x 13.64 M.pdf
 
O=C=O .pdf
                     O=C=O                                      .pdf                     O=C=O                                      .pdf
O=C=O .pdf
 
The start of the European Colonization is typically dated to 1492, a.pdf
The start of the European Colonization is typically dated to 1492, a.pdfThe start of the European Colonization is typically dated to 1492, a.pdf
The start of the European Colonization is typically dated to 1492, a.pdf
 
The institutions which act as mediator between savers and boorrowers.pdf
The institutions which act as mediator between savers and boorrowers.pdfThe institutions which act as mediator between savers and boorrowers.pdf
The institutions which act as mediator between savers and boorrowers.pdf
 
Solution Mitochondria is known as power house of the cell.It prod.pdf
Solution Mitochondria is known as power house of the cell.It prod.pdfSolution Mitochondria is known as power house of the cell.It prod.pdf
Solution Mitochondria is known as power house of the cell.It prod.pdf
 
Sewage before being disposed of either in river stream or on land, h.pdf
Sewage before being disposed of either in river stream or on land, h.pdfSewage before being disposed of either in river stream or on land, h.pdf
Sewage before being disposed of either in river stream or on land, h.pdf
 
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdf
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdfRelational database was proposed by Edgar Codd (of IBM Research) aro.pdf
Relational database was proposed by Edgar Codd (of IBM Research) aro.pdf
 
Option “D” is not true about the net neutrality.Favouring of net n.pdf
Option “D” is not true about the net neutrality.Favouring of net n.pdfOption “D” is not true about the net neutrality.Favouring of net n.pdf
Option “D” is not true about the net neutrality.Favouring of net n.pdf
 
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdf
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdfNaF will dissociate 100, and therefore the F- will have extra 0.25 .pdf
NaF will dissociate 100, and therefore the F- will have extra 0.25 .pdf
 
CO2 because the heaviest would have the most attr.pdf
                     CO2 because the heaviest would have the most attr.pdf                     CO2 because the heaviest would have the most attr.pdf
CO2 because the heaviest would have the most attr.pdf
 
Intensity of light source Io = 1000 countsIntensity after absorpti.pdf
Intensity of light source Io = 1000 countsIntensity after absorpti.pdfIntensity of light source Io = 1000 countsIntensity after absorpti.pdf
Intensity of light source Io = 1000 countsIntensity after absorpti.pdf
 
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdfI hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
I hereby explain the SDU (service data unit )and PDU ( protocol data.pdf
 
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdf
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdfHop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdf
Hop1 = 13, p2 = 13, and p3 = 13Ha at least one p is not equal.pdf
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

Hi Please find my code####### RainFall.java ###################.pdf

  • 1. Hi Please find my code: ####### RainFall.java ################### public class RainFall { private double[] monthlyRainFallArr; public RainFall(double[] rainFallArr) { monthlyRainFallArr = new double[12]; // creating an array to store monthly rainfall for(int i=0; i<12; i++) monthlyRainFallArr[i] = rainFallArr[i]; } public double getTotalRainFallForYear(){ double total = 0; for(int i=0; i<12; i++) total += monthlyRainFallArr[i]; return total; } // function to get average monthly rail fall public double getAverageMonthlyRainFall(){ double totalYear = getTotalRainFallForYear(); return totalYear/12; } // function to get month number with least rail fall public int getMonthWithLeastRainFall(){ int min_index = 0; for(int i=1; i<12; i++){ if(monthlyRainFallArr[i] < monthlyRainFallArr[min_index]){ min_index = i; } }
  • 2. return (min_index+1); } // function to get month number with most rail fall public int getMonthWithMostRainFall(){ int max_index = 0; for(int i=1; i<12; i++){ if(monthlyRainFallArr[i] > monthlyRainFallArr[max_index]){ max_index = i; } } return (max_index+1); } } ############## RainFallTest.java ################## import java.util.Scanner; public class RainFallTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double rainFallArr[] = new double[12]; System.out.println("Enter rain fall data for 12 month: "); for(int i=0; i<12; i++){ System.out.print("Rail Fall data for "+(i+1)+" month: "); rainFallArr[i] = sc.nextDouble(); } RainFall rainfall = new RainFall(rainFallArr); System.out.println("Total rain fall for year: "+rainfall.getTotalRainFallForYear());
  • 3. System.out.println("Average monthly rain fall: "+rainfall.getAverageMonthlyRainFall()); System.out.println("Month Number with least rainfall: "+rainfall.getMonthWithLeastRainFall()); System.out.println("Month Number with most rainfall: "+rainfall.getMonthWithMostRainFall()); } } /* Sample Output: Enter rain fall data for 12 month: Rail Fall data for 1 month: 45.43 Rail Fall data for 2 month: 48.76 Rail Fall data for 3 month: 46.56 Rail Fall data for 4 month: 47.23 Rail Fall data for 5 month: 44.32 Rail Fall data for 6 month: 43.23 Rail Fall data for 7 month: 58.76 Rail Fall data for 8 month: 55.65 Rail Fall data for 9 month: 50.76 Rail Fall data for 10 month: 49.12 Rail Fall data for 11 month: 37.45 Rail Fall data for 12 month: 38.00 Total rain fall for year: 565.27 Average monthly rain fall: 47.10583333333333 Month Number with least rainfall: 11 Month Number with most rainfall: 7 */ Solution Hi Please find my code: ####### RainFall.java ################### public class RainFall { private double[] monthlyRainFallArr; public RainFall(double[] rainFallArr) {
  • 4. monthlyRainFallArr = new double[12]; // creating an array to store monthly rainfall for(int i=0; i<12; i++) monthlyRainFallArr[i] = rainFallArr[i]; } public double getTotalRainFallForYear(){ double total = 0; for(int i=0; i<12; i++) total += monthlyRainFallArr[i]; return total; } // function to get average monthly rail fall public double getAverageMonthlyRainFall(){ double totalYear = getTotalRainFallForYear(); return totalYear/12; } // function to get month number with least rail fall public int getMonthWithLeastRainFall(){ int min_index = 0; for(int i=1; i<12; i++){ if(monthlyRainFallArr[i] < monthlyRainFallArr[min_index]){ min_index = i; } } return (min_index+1); } // function to get month number with most rail fall public int getMonthWithMostRainFall(){
  • 5. int max_index = 0; for(int i=1; i<12; i++){ if(monthlyRainFallArr[i] > monthlyRainFallArr[max_index]){ max_index = i; } } return (max_index+1); } } ############## RainFallTest.java ################## import java.util.Scanner; public class RainFallTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double rainFallArr[] = new double[12]; System.out.println("Enter rain fall data for 12 month: "); for(int i=0; i<12; i++){ System.out.print("Rail Fall data for "+(i+1)+" month: "); rainFallArr[i] = sc.nextDouble(); } RainFall rainfall = new RainFall(rainFallArr); System.out.println("Total rain fall for year: "+rainfall.getTotalRainFallForYear()); System.out.println("Average monthly rain fall: "+rainfall.getAverageMonthlyRainFall()); System.out.println("Month Number with least rainfall: "+rainfall.getMonthWithLeastRainFall()); System.out.println("Month Number with most rainfall: "+rainfall.getMonthWithMostRainFall()); } }
  • 6. /* Sample Output: Enter rain fall data for 12 month: Rail Fall data for 1 month: 45.43 Rail Fall data for 2 month: 48.76 Rail Fall data for 3 month: 46.56 Rail Fall data for 4 month: 47.23 Rail Fall data for 5 month: 44.32 Rail Fall data for 6 month: 43.23 Rail Fall data for 7 month: 58.76 Rail Fall data for 8 month: 55.65 Rail Fall data for 9 month: 50.76 Rail Fall data for 10 month: 49.12 Rail Fall data for 11 month: 37.45 Rail Fall data for 12 month: 38.00 Total rain fall for year: 565.27 Average monthly rain fall: 47.10583333333333 Month Number with least rainfall: 11 Month Number with most rainfall: 7 */