Download Fahrenheit to Centigrade Conversion Homework Solution and more Assignments Computer Science in PDF only on Docsity! Fahrenheit to Centigrade Conversion Homework #1 By Purushotham V. Bangalore CS 441/632/732 Parallel Computing Jan 27, 2004 Problem Specification Write a program that will read temperature in Fahrenheit scale, converts it to Centigrade scale, and print the values of temperature in Fahrenheit and Centigrade scales. The program must work on positive and negative values and accept decimals. Program Design In order to solve the given problem we need to perform the following steps: a) read in a floating point number b) compute the corresponding value in centigrade scale c) display the input and computed value We can read a number using the Keyboard class provided in the text book. Conversion from Fahrenheit to Centigrade scale can be performed using the formula C = 5/9 * (F – 32), where F is the temperature in Fahrenheit scale and C is the corresponding temperature in Centigrade scale. The display can be done using the println method of the System.out object. Testing Plan There are 3 main steps in the program and we should test all 3 steps. Step (c) is simple since we are relying on System class. We can test Step (a) by printing the values read to make sure the value read using the Keyboard class is the one we entered. Step (b) is the most important piece that requires good test cases. By looking at the formula we can observe that if F=32, then C=0 and if F=0, C=5/9*(-32)=-17.78 (if we round off at 2 significant digits). Similarly we can determine that F=100 gives C=37.78 and F=212 gives C=100. Test Cases The test cases are shown in the table below: Test Case Number Input Values Expected Output Values 1 32 0 2 212 100 3 100 37.78 4 0 -17.78 Analysis and Conclusions Conversion of temperatures from Fahrenheit scale to Centigrade scale was accomplished using the formula C = 5/9*(F – 32). It is important to declare the different variables with the correct type in order to get the correct result. Also correct translation of the formula into Java language is essential to get correct results. Computing the expected results by hand before writing and testing the program allowed us to make sure the results of the program were correct. Test results validate that the results produced by the program were correct. 1