-

2011年8月4日星期四

How to calculate average rainfall for 6 months in java?

-that is what i done so far but i am lost now





import javax.swing.*;

class practice

{



public static void main(String[] args)

{



// declare array

//fill array with data for a week

int averagerainfall[]= new int[6];

String months[] = {"jan","feb","mar","apr","may","jun","ju鈥?br>


int s=0;

int x=0;



for (int i=0; i <averagerainfall.length; i++)



{

// input data and convert it to an Integer

s = Integer.parseInt(JOptionPane.showInputDi鈥?enter the average rainfall per month" +(i+1)));

averagerainfall[i] =s;

}



Displaydata (averagerainfall,months);

}// main



public static void Displaydata(int averagerainfall[],String months[] )

{

// declare variable

int max=0;

String x="";



for (int i=0; i<6; i++)



{

if (averagerainfall[i] >max)



{



max=averagerainfall[i];

x=months[i];



}



System.out.print(" The amount of rainfall is " + averagerainfall[i]+ ", on ");

System.out.println(months[i]

double x = "";

System.out.println("Average rainfall: " + (x/3) ;



} // end of method DisplayData





System.out.println( "The average rainfall is, " + max + " and that is on " + x );



// Display Results

} // end of main



} // end of class



and this is what the program should be like...



This program must contain at least two methods (main and one or more other method(s)). Write a method that inputs the length of rainfall in centimetres for each of the six months January to July into an array.



This array should be passed to another method averageRainfall which calculates the average rainfall for the six months. This method should return the average rainfall to the calling method where it is output to the screen..



help please need it ASAP.. thank you

没有评论:

发表评论