4 Study the CupConverter app on pages 297300 Write a similar

4. Study the CupConverter app on pages 297-300. Write a similar app. that asks the user for a temperature in degrees Fahrenheit and displays its equivalent in Celsius. Find the formula needed via a web search. You must use methods to accomplish these tasks (similar to pages 298-9), and verify that your app produces analytically correct output. >Provide hardcopy of your code on paper and also softcopy of your CST150xxHW5tempConverter .java via an email, where xx -your initials.

Solution

CST150xxHW5tempConverter.java

import java.text.DecimalFormat;
import java.util.Scanner;


public class CST150xxHW5tempConverter {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       DecimalFormat df = new DecimalFormat(\"0.00\");
       System.out.println(\"Enter the temparature in Fahrenheit: \");
       double fahrenheit = scan.nextDouble();
       double celsius = convertToCelsius(fahrenheit);
       System.out.println(\"Temparature in celsius is \"+df.format(celsius));
   }
   public static double convertToCelsius(double fahrenheit){
       double celsius = ( 5 /(double) 9 ) * ( fahrenheit - 32 );
       return celsius;
    }

}

Output:

Enter the temparature in Fahrenheit:
100
Temparature in celsius is 37.78

 4. Study the CupConverter app on pages 297-300. Write a similar app. that asks the user for a temperature in degrees Fahrenheit and displays its equivalent in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site