import java.io.*; //----------------------------------------------------------------- // CS100 P1 Q1 // // This program prompts the user for a temperature in Celcius, // converts the temperature into Fahrenheit and prints out the // convereted temperature. // // Author : Wei Tsang Ooi (weitsang@cs.cornell.edu) // Date : 2 July 1999 //----------------------------------------------------------------- class TemperatureConverter { //------------------------------------------------------------- // getInput // // input : none // return : the value input by user // // This method prompts the user for input, and returns the value // input by the user. //------------------------------------------------------------- private static float getInput() throws IOException { BufferedReader stdin; stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter degree in Celcius : "); String input = stdin.readLine(); Float f = Float.valueOf(input); return f.floatValue(); } //------------------------------------------------------------- // convert // // input : a temperature in Celcius // return : the equvalent temperature in Fahrenheit //------------------------------------------------------------- private static float celciusToFahrenheit(float celcius) { return ((celcius*9)/5) + 32; } //------------------------------------------------------------- // printFahrenheit // // input : a temperature in Fahrenheit // return : none // // Output the temperature on the screen. //------------------------------------------------------------- private static void printFahrenheit (float temperature) { System.out.println("This is equal to " + temperature + " Fahrenheit."); } public static void main(String[] args) throws IOException { float celcius = getInput(); float fahrenheit = celciusToFahrenheit(celcius); printFahrenheit(fahrenheit); } }