import java.io.*; public class HIApp { public static void main(String [] args) throws IOException { //Define input variable to read from keyboard BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //Define a boolean to control looping for input boolean repeat = true; //Define string to store user input so i can be echoed in case of error String userInput = ""; //Define variable to store temperature provided by user int inputTemperature = 0; //Define variable to store humidity provided by user int inputHumidity = 0; //Instantiate a heat index calculator object HICalc hindex1 = new HICalc(); while(repeat){ //Wishful thinking...user may enter value correctly first time repeat = false; //Prompt user for a temperature value System.out.println("Please enter an integer temperature between " + "80 and 110 (inclusive) representing degrees Fahrenheit."); try{ //The following statements may cause an error if user enters string //that cannot be converted to integer. userInput = in.readLine(); inputTemperature = Integer.parseInt( userInput); //Set temperature equal to value provided by user. //May produce error if not in range. hindex1.setTemp(inputTemperature); } catch(NumberFormatException e1) { System.out.println ("You entered: " + userInput); System.out.println ("This is not an integer number."); //Give user another chance to enter valid value repeat = true; } catch(IllegalArgumentException e2) { System.out.println (e2.getMessage()); //Give user another chance to enter valid value repeat = true; } } repeat = true; //Finally have a valid temperature; go on to next step //Now ask user for relative humidity value while(repeat) { //Wishful thinking...user may enter value correctly first time repeat = false; //Prompt user for a relative humidity value System.out.println("Please enter an integer between" + "0 and 100 (inclusive) to represent the" + "relative humidity percentage."); try{ //The following statement may cause an error if user enters string //that cannot be converted to integer. userInput = in.readLine(); inputHumidity = Integer.parseInt(userInput); //Set humidity equal to value provided by user. //May produce error if not in range. hindex1.setHumid(inputHumidity); } catch(NumberFormatException e3) { System.out.println("You entered: " + userInput); System.out.println("This is not an integer number."); repeat = true; } catch(IllegalArgumentException e4) { System.out.println (e4.getMessage()); repeat = true; } } //We have valid input values. Now can compute heat index. System.out.println("Now computing the heat index ..."); //Compute heat index value hindex1.computeHi(); //Print out temperature, humidity, and heat index value System.out.println(hindex1.toString()); //Print out warning for heat index value System.out.println(hindex1.showWarning()); } }