Programming Activity 22 Complete Chapter 2 Programming Activ

Programming Activity 2-2 Complete Chapter 2, Programming Activity 2: Temperature Conversion. Although you should test your program with different values for the Fahrenheit temperature, use 75 in the final version that you submit. Your output should appear as follows: 75 in Fahrenheit is 23.88888888888889 in Celsius. 23.88888888888889 in Celsius is 75 in Fahrenheit. Notes: 1. Note that the temperature conversion formulas given in the textbook have a subtle order of operations difference. The formula that applies to part 3 is: Tc = 5 / 9 * (Tf - 32). It has parentheses around the subtraction operation because the subtraction occurs before the other operations. The formula that applies to part 5 is: Tf = 9 / 5 * Tc + 32. It does not have parentheses around the addition operation because the addition occurs after the other operations. 2. In both formulas, the integer division (such as 9 / 5) must be changed to a double division by either explicitly type casting the numerator to a double ((double)9 / 5) or by using a double literal for the numerator instead of an integer literal (9.0 / 5). 3. Note that this program uses mixed data types. The temperature in Fahrenheit is specified to be declared as an int. The temperature in Celsius is specified to be declared as a double. 4. Since part 5 requires an explicit type cast of its formula result (to an int) prior to being assigned to the int temperature in Fahrenheit variable, the following example code is provided for you for this somewhat tricky step. temperatureF = (int)(9.0 / 5 * temperatureC + FREEZING_POINT); Of course, use your own variable names if they are different from the ones used here. Upload your zipped assignment folder, which contains the java and class files. /* Temperature Conversion Anderson, Franceschi */ public class TemperatureConversion { public static void main(String [] args) { //***** 1. declare any constants here // Part 1 student code starts here: // Part 1 student code ends here. //***** 2. declare temperature in Fahrenheit as an int // Part 2 student code starts here: // Part 2 student code ends here. //***** 3. calculate equivalent Celsius temperature as a double // Part 3 student code starts here: // Part 3 student code ends here. //***** 4. output the temperature in Celsius // Part 4 student code starts here: // Part 4 student code ends here. //***** 5. convert Celsius temperature back to Fahrenheit // Part 5 student code starts here: // Part 5 student code ends here. //***** 6. output Fahrenheit temperature to check correctness // Part 6 student code starts here: // Part 6 student code ends here. } }

Solution

Please follow the code and comments for description :

CODE :

import java.util.Scanner; // required imports for the code

public class TemperatureConversion { // class thst has the relative methods

    public static void main(String[] args) { // main driver method
        // declare any constants here
        Scanner sc = new Scanner (System.in);
      
        // declare temperature in Fahrenheit as an int
        int Tf = 0;
        double Tc;
        System.out.println(\"Please Enter the Temperature in Fahrenheit : \");
        Tf = sc.nextInt();
      
        // calculate equivalent Celsius temperature as a double
        Tc = (double)5 / 9 * (Tf - 32);
      
        // output the temperature in Celsius
        System.out.println(\"The Temperature \"+Tf+\" in Celsius is : \"+Tc);
      
        // convert Celsius temperature back to Fahrenheit
        Tf = (int) ((double)9 / 5 * Tc + 32);
      
       // output Fahrenheit temperature to check correctness
        System.out.println(\"The Temperature \"+Tc+\" in Fahreheit is : \"+Tf);       
    }
}

OUTPUT :

Please Enter the Temperature in Fahrenheit :
75
The Temperature 75 in Celsius is : 23.88888888888889
The Temperature 23.88888888888889 in Fahreheit is : 75

Hope this is helpful.

Programming Activity 2-2 Complete Chapter 2, Programming Activity 2: Temperature Conversion. Although you should test your program with different values for the
Programming Activity 2-2 Complete Chapter 2, Programming Activity 2: Temperature Conversion. Although you should test your program with different values for the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site