I'm supposed to display the rainfall value for the STATE that I want to search. How do I go about doing this?
rainfall class:
package rainfallassignment;
public class StateRainfall {
double rainAmt[]; //declare array value entered by user
int num_state = 11; //number of states in west malaysia
public StateRainfall(double rain[]) {
rainAmt = rain;
}
}
Test program:
package rainfallassignment;
import java.util.Scanner;
public class TestRainfall {
public static void main(String[] arg) {
Scanner reader = new Scanner(System.in);
//declare constant to store size of array
int num_state = 11;
//declare array to store rainfall data
double rain[] = new double[num_state];
//array representing states
String[] state = {"Perlis", "Kedah", "Penang", "Perak",
"Kelantan", "Terengganu", "Pahang",
"Selangor", "Negeri Sembilan", "Malacca", "Johor"};
for (int i = 0; i < num_state; i++) {
System.out.println("Enter Rain value for each state: "
+ state[i] + ": ");
rain[i] = reader.nextDouble();
}
//create rainfall object
StateRainfall rain1 = new StateRainfall(rain);
for (int i = 0; i < num_state; i++) {
System.out.println("Rainfall for " + state[i] + " is: " + rain[i]);
}
}
}
Is there a special command I should use to search and display the rainfall for a particular state?