SlideShare a Scribd company logo
1 of 7
Download to read offline
//tested on Eclipse
/*************Rainfall.java*************/
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class RainFall {
/*Data member variable*/
private double monthlyRainFall;
private double monthsRainFall[]=new double[12];
private int month=0;
private double maxRain=0.0;
private int maxrainMonth;
private double minRain=0.0;
private int minRainMonth;
/*creating map for storing month*/
Map monthMap=new HashMap();
Scanner input=new Scanner(System.in);
/*Initializing map with value while default constructor*/
public RainFall(){
monthMap.put(0, "January");
monthMap.put(1, "February");
monthMap.put(2, "March");
monthMap.put(3, "April");
monthMap.put(4, "May");
monthMap.put(5, "June");
monthMap.put(6, "July");
monthMap.put(7, "August");
monthMap.put(8, "September");
monthMap.put(9, "October");
monthMap.put(10, "November");
monthMap.put(11, "December");
}
/*Getting monthlyRainFall*/
public double getMonthlyRainFall() {
return monthlyRainFall;
}
/*Setting monthly rainfall If it is negative then it loops until positive */
public void setMonthlyRainFall(double monthlyRainFall) {
while(monthlyRainFall<0){
System.out.println("Please Enter positive value of monthly rainfall");
monthlyRainFall=input.nextDouble();
}
monthsRainFall[month++]=monthlyRainFall;
}
/*Getting average month rain fall*/
public void averageMonthlyRainFall(){
double totalRainFall=0;
/*first calculate totalRain fall after that divide it total month*/
for(int i=0;imonthsRainFall[i]){
minRain=monthsRainFall[i];
minRainMonth=i;
}
}
System.out.println("Min Rain Month Fall: "+monthMap.get(minRainMonth));
}
/*Main method start*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
/*Creating instance of rainFall class*/
RainFall rainFall=new RainFall();
/*getting rainfall for each month from user*/
for(int i=0;i<12;i++){
System.out.println("Please Enter rainFall for "+(i+1)+" Month");
rainFall.setMonthlyRainFall(sc.nextDouble());
}
/*Average Monthly rainfall*/
rainFall.averageMonthlyRainFall();
/*Total Rain Fall in a year*/
rainFall.totalRainFall();
/*Max rainFall Month*/
rainFall.maxRainFallMonth();
/*Minimum rainFall Month*/
rainFall.minRainFallMonth();
sc.close();
}
}
/***************output************/
Please Enter rainFall for 1 Month
121
Please Enter rainFall for 2 Month
134
Please Enter rainFall for 3 Month
54
Please Enter rainFall for 4 Month
167
Please Enter rainFall for 5 Month
256
Please Enter rainFall for 6 Month
456
Please Enter rainFall for 7 Month
78
Please Enter rainFall for 8 Month
290
Please Enter rainFall for 9 Month
176
Please Enter rainFall for 10 Month
263
Please Enter rainFall for 11 Month
100
Please Enter rainFall for 12 Month
189
Average Monthly Rain Fall: 190.33
Total Rain Fall for the year: 2284
Max Rain Month Fall: June
Min Rain Month Fall: March
Thanks a lot. If you have any doubt. Please let me know
Solution
//tested on Eclipse
/*************Rainfall.java*************/
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class RainFall {
/*Data member variable*/
private double monthlyRainFall;
private double monthsRainFall[]=new double[12];
private int month=0;
private double maxRain=0.0;
private int maxrainMonth;
private double minRain=0.0;
private int minRainMonth;
/*creating map for storing month*/
Map monthMap=new HashMap();
Scanner input=new Scanner(System.in);
/*Initializing map with value while default constructor*/
public RainFall(){
monthMap.put(0, "January");
monthMap.put(1, "February");
monthMap.put(2, "March");
monthMap.put(3, "April");
monthMap.put(4, "May");
monthMap.put(5, "June");
monthMap.put(6, "July");
monthMap.put(7, "August");
monthMap.put(8, "September");
monthMap.put(9, "October");
monthMap.put(10, "November");
monthMap.put(11, "December");
}
/*Getting monthlyRainFall*/
public double getMonthlyRainFall() {
return monthlyRainFall;
}
/*Setting monthly rainfall If it is negative then it loops until positive */
public void setMonthlyRainFall(double monthlyRainFall) {
while(monthlyRainFall<0){
System.out.println("Please Enter positive value of monthly rainfall");
monthlyRainFall=input.nextDouble();
}
monthsRainFall[month++]=monthlyRainFall;
}
/*Getting average month rain fall*/
public void averageMonthlyRainFall(){
double totalRainFall=0;
/*first calculate totalRain fall after that divide it total month*/
for(int i=0;imonthsRainFall[i]){
minRain=monthsRainFall[i];
minRainMonth=i;
}
}
System.out.println("Min Rain Month Fall: "+monthMap.get(minRainMonth));
}
/*Main method start*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
/*Creating instance of rainFall class*/
RainFall rainFall=new RainFall();
/*getting rainfall for each month from user*/
for(int i=0;i<12;i++){
System.out.println("Please Enter rainFall for "+(i+1)+" Month");
rainFall.setMonthlyRainFall(sc.nextDouble());
}
/*Average Monthly rainfall*/
rainFall.averageMonthlyRainFall();
/*Total Rain Fall in a year*/
rainFall.totalRainFall();
/*Max rainFall Month*/
rainFall.maxRainFallMonth();
/*Minimum rainFall Month*/
rainFall.minRainFallMonth();
sc.close();
}
}
/***************output************/
Please Enter rainFall for 1 Month
121
Please Enter rainFall for 2 Month
134
Please Enter rainFall for 3 Month
54
Please Enter rainFall for 4 Month
167
Please Enter rainFall for 5 Month
256
Please Enter rainFall for 6 Month
456
Please Enter rainFall for 7 Month
78
Please Enter rainFall for 8 Month
290
Please Enter rainFall for 9 Month
176
Please Enter rainFall for 10 Month
263
Please Enter rainFall for 11 Month
100
Please Enter rainFall for 12 Month
189
Average Monthly Rain Fall: 190.33
Total Rain Fall for the year: 2284
Max Rain Month Fall: June
Min Rain Month Fall: March
Thanks a lot. If you have any doubt. Please let me know

More Related Content

More from sutharbharat59

1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf
sutharbharat59
 
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
sutharbharat59
 
In chemistry, hybridisation (or hybridization) is.pdf
                     In chemistry, hybridisation (or hybridization) is.pdf                     In chemistry, hybridisation (or hybridization) is.pdf
In chemistry, hybridisation (or hybridization) is.pdf
sutharbharat59
 
To convert html code into Java servlet you have to write all html ta.pdf
To convert html code into Java servlet you have to write all html ta.pdfTo convert html code into Java servlet you have to write all html ta.pdf
To convert html code into Java servlet you have to write all html ta.pdf
sutharbharat59
 
The implementation algorithm whose amortized complexity is O (1) to .pdf
The implementation algorithm whose amortized complexity is O (1) to .pdfThe implementation algorithm whose amortized complexity is O (1) to .pdf
The implementation algorithm whose amortized complexity is O (1) to .pdf
sutharbharat59
 
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdfThe correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
sutharbharat59
 
SKIN SENSORY ORGANThe human skin is the external covering of the .pdf
SKIN SENSORY ORGANThe human skin is the external covering of the .pdfSKIN SENSORY ORGANThe human skin is the external covering of the .pdf
SKIN SENSORY ORGANThe human skin is the external covering of the .pdf
sutharbharat59
 
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdf
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdfQues-1Part-a Mitosis it is a somatic cell division in an organi.pdf
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdf
sutharbharat59
 
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdfProportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
sutharbharat59
 
Q) The passage of traits from parents of offspring is called A H.pdf
Q) The passage of traits from parents of offspring is called A H.pdfQ) The passage of traits from parents of offspring is called A H.pdf
Q) The passage of traits from parents of offspring is called A H.pdf
sutharbharat59
 

More from sutharbharat59 (20)

1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf
 
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
 
In chemistry, hybridisation (or hybridization) is.pdf
                     In chemistry, hybridisation (or hybridization) is.pdf                     In chemistry, hybridisation (or hybridization) is.pdf
In chemistry, hybridisation (or hybridization) is.pdf
 
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdfRPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
 
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdfy^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
 
 Fe(s) + Mn2+(aq) Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
 Fe(s) + Mn2+(aq)  Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf Fe(s) + Mn2+(aq)  Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
 Fe(s) + Mn2+(aq) Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
 
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdfWhen Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
 
To convert html code into Java servlet you have to write all html ta.pdf
To convert html code into Java servlet you have to write all html ta.pdfTo convert html code into Java servlet you have to write all html ta.pdf
To convert html code into Java servlet you have to write all html ta.pdf
 
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdfTherapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
 
They trade away higher fecundity for future reproduction.Being ite.pdf
They trade away higher fecundity for future reproduction.Being ite.pdfThey trade away higher fecundity for future reproduction.Being ite.pdf
They trade away higher fecundity for future reproduction.Being ite.pdf
 
The statements that are consistent with facts known about membrane a.pdf
The statements that are consistent with facts known about membrane a.pdfThe statements that are consistent with facts known about membrane a.pdf
The statements that are consistent with facts known about membrane a.pdf
 
The implementation algorithm whose amortized complexity is O (1) to .pdf
The implementation algorithm whose amortized complexity is O (1) to .pdfThe implementation algorithm whose amortized complexity is O (1) to .pdf
The implementation algorithm whose amortized complexity is O (1) to .pdf
 
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdfThe correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
 
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdfStep1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
 
SKIN SENSORY ORGANThe human skin is the external covering of the .pdf
SKIN SENSORY ORGANThe human skin is the external covering of the .pdfSKIN SENSORY ORGANThe human skin is the external covering of the .pdf
SKIN SENSORY ORGANThe human skin is the external covering of the .pdf
 
a) FlaseIn terms of trasing volume it is by far the largest market.pdf
a) FlaseIn terms of trasing volume it is by far the largest market.pdfa) FlaseIn terms of trasing volume it is by far the largest market.pdf
a) FlaseIn terms of trasing volume it is by far the largest market.pdf
 
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdf
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdfQues-1Part-a Mitosis it is a somatic cell division in an organi.pdf
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdf
 
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdfProportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
 
POS system is a networked invironment where a main computer linked t.pdf
POS system is a networked invironment where a main computer linked t.pdfPOS system is a networked invironment where a main computer linked t.pdf
POS system is a networked invironment where a main computer linked t.pdf
 
Q) The passage of traits from parents of offspring is called A H.pdf
Q) The passage of traits from parents of offspring is called A H.pdfQ) The passage of traits from parents of offspring is called A H.pdf
Q) The passage of traits from parents of offspring is called A H.pdf
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 

tested on EclipseRainfall.javaimpo.pdf

  • 1. //tested on Eclipse /*************Rainfall.java*************/ import java.text.DecimalFormat; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class RainFall { /*Data member variable*/ private double monthlyRainFall; private double monthsRainFall[]=new double[12]; private int month=0; private double maxRain=0.0; private int maxrainMonth; private double minRain=0.0; private int minRainMonth; /*creating map for storing month*/ Map monthMap=new HashMap(); Scanner input=new Scanner(System.in); /*Initializing map with value while default constructor*/ public RainFall(){ monthMap.put(0, "January"); monthMap.put(1, "February"); monthMap.put(2, "March"); monthMap.put(3, "April"); monthMap.put(4, "May"); monthMap.put(5, "June"); monthMap.put(6, "July"); monthMap.put(7, "August"); monthMap.put(8, "September"); monthMap.put(9, "October"); monthMap.put(10, "November"); monthMap.put(11, "December"); } /*Getting monthlyRainFall*/ public double getMonthlyRainFall() {
  • 2. return monthlyRainFall; } /*Setting monthly rainfall If it is negative then it loops until positive */ public void setMonthlyRainFall(double monthlyRainFall) { while(monthlyRainFall<0){ System.out.println("Please Enter positive value of monthly rainfall"); monthlyRainFall=input.nextDouble(); } monthsRainFall[month++]=monthlyRainFall; } /*Getting average month rain fall*/ public void averageMonthlyRainFall(){ double totalRainFall=0; /*first calculate totalRain fall after that divide it total month*/ for(int i=0;imonthsRainFall[i]){ minRain=monthsRainFall[i]; minRainMonth=i; } } System.out.println("Min Rain Month Fall: "+monthMap.get(minRainMonth)); } /*Main method start*/ public static void main(String[] args) { Scanner sc=new Scanner(System.in); /*Creating instance of rainFall class*/ RainFall rainFall=new RainFall(); /*getting rainfall for each month from user*/ for(int i=0;i<12;i++){ System.out.println("Please Enter rainFall for "+(i+1)+" Month"); rainFall.setMonthlyRainFall(sc.nextDouble()); } /*Average Monthly rainfall*/ rainFall.averageMonthlyRainFall(); /*Total Rain Fall in a year*/ rainFall.totalRainFall();
  • 3. /*Max rainFall Month*/ rainFall.maxRainFallMonth(); /*Minimum rainFall Month*/ rainFall.minRainFallMonth(); sc.close(); } } /***************output************/ Please Enter rainFall for 1 Month 121 Please Enter rainFall for 2 Month 134 Please Enter rainFall for 3 Month 54 Please Enter rainFall for 4 Month 167 Please Enter rainFall for 5 Month 256 Please Enter rainFall for 6 Month 456 Please Enter rainFall for 7 Month 78 Please Enter rainFall for 8 Month 290 Please Enter rainFall for 9 Month 176 Please Enter rainFall for 10 Month 263 Please Enter rainFall for 11 Month 100 Please Enter rainFall for 12 Month 189 Average Monthly Rain Fall: 190.33 Total Rain Fall for the year: 2284 Max Rain Month Fall: June Min Rain Month Fall: March
  • 4. Thanks a lot. If you have any doubt. Please let me know Solution //tested on Eclipse /*************Rainfall.java*************/ import java.text.DecimalFormat; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class RainFall { /*Data member variable*/ private double monthlyRainFall; private double monthsRainFall[]=new double[12]; private int month=0; private double maxRain=0.0; private int maxrainMonth; private double minRain=0.0; private int minRainMonth; /*creating map for storing month*/ Map monthMap=new HashMap(); Scanner input=new Scanner(System.in); /*Initializing map with value while default constructor*/ public RainFall(){ monthMap.put(0, "January"); monthMap.put(1, "February"); monthMap.put(2, "March"); monthMap.put(3, "April"); monthMap.put(4, "May"); monthMap.put(5, "June"); monthMap.put(6, "July"); monthMap.put(7, "August"); monthMap.put(8, "September"); monthMap.put(9, "October"); monthMap.put(10, "November");
  • 5. monthMap.put(11, "December"); } /*Getting monthlyRainFall*/ public double getMonthlyRainFall() { return monthlyRainFall; } /*Setting monthly rainfall If it is negative then it loops until positive */ public void setMonthlyRainFall(double monthlyRainFall) { while(monthlyRainFall<0){ System.out.println("Please Enter positive value of monthly rainfall"); monthlyRainFall=input.nextDouble(); } monthsRainFall[month++]=monthlyRainFall; } /*Getting average month rain fall*/ public void averageMonthlyRainFall(){ double totalRainFall=0; /*first calculate totalRain fall after that divide it total month*/ for(int i=0;imonthsRainFall[i]){ minRain=monthsRainFall[i]; minRainMonth=i; } } System.out.println("Min Rain Month Fall: "+monthMap.get(minRainMonth)); } /*Main method start*/ public static void main(String[] args) { Scanner sc=new Scanner(System.in); /*Creating instance of rainFall class*/ RainFall rainFall=new RainFall(); /*getting rainfall for each month from user*/ for(int i=0;i<12;i++){ System.out.println("Please Enter rainFall for "+(i+1)+" Month"); rainFall.setMonthlyRainFall(sc.nextDouble()); }
  • 6. /*Average Monthly rainfall*/ rainFall.averageMonthlyRainFall(); /*Total Rain Fall in a year*/ rainFall.totalRainFall(); /*Max rainFall Month*/ rainFall.maxRainFallMonth(); /*Minimum rainFall Month*/ rainFall.minRainFallMonth(); sc.close(); } } /***************output************/ Please Enter rainFall for 1 Month 121 Please Enter rainFall for 2 Month 134 Please Enter rainFall for 3 Month 54 Please Enter rainFall for 4 Month 167 Please Enter rainFall for 5 Month 256 Please Enter rainFall for 6 Month 456 Please Enter rainFall for 7 Month 78 Please Enter rainFall for 8 Month 290 Please Enter rainFall for 9 Month 176 Please Enter rainFall for 10 Month 263 Please Enter rainFall for 11 Month 100 Please Enter rainFall for 12 Month 189
  • 7. Average Monthly Rain Fall: 190.33 Total Rain Fall for the year: 2284 Max Rain Month Fall: June Min Rain Month Fall: March Thanks a lot. If you have any doubt. Please let me know