Simple Java class that converts Fahrenheit to Celsius. Read comments above each statement to understand the procedure.
The purpose of this tutorial is to get you thinking like a programmer.
Steps (Logic)
1. John asks you to build a program that converts Fahrenheit to Celsius.
2. You research for the mathematical formula that converts Fahrenheit to Celsius.
3. You know that John wants to be able to enter any value, so you'll need to create a prompt for John, instead of just hard-coding a particular value into the program.
4. Once John enters the value, the program will need to process the necessary calculations.
5. Finally, the program will need to provide John with the answer.
High-Level Flow
1. Prompt User to enter a Fahrenheit Value
2. Receive/store the value
3. Use the Fahrenheit to Celsius equation to process the conversion
4. Display the results
Special note. Research the difference between int and double in Java. If you divide 5/2, you will not receive 2.5 as expected, you'll receive 2. To make sure that the correct value is displayed, divide with a double (5.0/2) to let Java know it's a double.
The Scanner class allows the programmer to request inputs from the user before continuing with the code. You'll notice the Scanner class's nextDouble() method used in this code. The program waits for the user to enter a decimal value (double) before continuing.
The purpose of this tutorial is to get you thinking like a programmer.
Steps (Logic)
1. John asks you to build a program that converts Fahrenheit to Celsius.
2. You research for the mathematical formula that converts Fahrenheit to Celsius.
3. You know that John wants to be able to enter any value, so you'll need to create a prompt for John, instead of just hard-coding a particular value into the program.
4. Once John enters the value, the program will need to process the necessary calculations.
5. Finally, the program will need to provide John with the answer.
High-Level Flow
1. Prompt User to enter a Fahrenheit Value
2. Receive/store the value
3. Use the Fahrenheit to Celsius equation to process the conversion
4. Display the results
Special note. Research the difference between int and double in Java. If you divide 5/2, you will not receive 2.5 as expected, you'll receive 2. To make sure that the correct value is displayed, divide with a double (5.0/2) to let Java know it's a double.
The Scanner class allows the programmer to request inputs from the user before continuing with the code. You'll notice the Scanner class's nextDouble() method used in this code. The program waits for the user to enter a decimal value (double) before continuing.
Comments
Post a Comment