Presentation is loading. Please wait.

Presentation is loading. Please wait.

TemperatureConversion

Similar presentations


Presentation on theme: "TemperatureConversion"— Presentation transcript:

1 TemperatureConversion
Create a TemperatureConversion client class as follows: Enter a prompt for the Fahrenheit temperature in the console (using the Scanner class), and allow the user to enter the temperature there. Convert the temperature from Fahrenheit to Celsius Convert the temperature from Fahrenheit to Kelvin Print a message to the console that shows the conversion, such as: 50.0 F = 10.0 C 50.0 F = K Do the same thing to allow the user to enter the temperature in Celsius and then print the conversion to Fahrenheit and Kelvin. 0.0 C = 32.0 F 0.0 C = K Do the same thing to allow the user to enter the temperature in Kelvin and then print the conversion to Fahrenheit and Celsius. K = 50.0 F K = 10.0 C The conversion formulas can easily be found on the internet Please try these conversions where Fahrenheit = 50 and Celsius = 0. Also try a couple of other examples of your choice to verify that the program is working correctly.

2 Terminal I/O for Different Data types
Scanner class: reads from the input stream **** new for Java 5.0, but not tested on AP exam Here are the methods in the Scanner class: METHOD DESCRIPTION double nextDouble() Returns the first double in the input line. Leading and trailing spaces are ignored. int nextInt() Returns the first integer in the input line. Leading and trailing spaces are ignored. String nextLine() Returns the input line, including leading and trailing spaces. Warning: A leading newline is returned as an empty string.

3 Terminal I/O for Different Data types
The following program illustrates the major features of terminal I/O: import java.util.Scanner; public class TestTerminalIO { public static void main (String [] args) { Scanner in = new Scanner(System.in); System.out.print ("Enter your name (a string): "); String name = in.nextLine(); System.out.print("Enter your age (an integer): "); int age = in.nextInt(); System.out.print("Enter your weight (a double): "); double weight = in.nextDouble();

4 Terminal I/O for Different Data types
System.out.println ("Greetings " + name + ". You are " + age + " years old and you weigh " + weight + " pounds."); }


Download ppt "TemperatureConversion"

Similar presentations


Ads by Google