Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your program should allow the user to run it as many times as wished. Use an app

ID: 3689584 • Letter: Y

Question

Your program should allow the user to run it as many times as wished. Use an appropriate loop. Your program should implement the following tasks: Display to the user the purpose of this program In this program you will be converting temperature entered by the user in degree Fahrenheit to Degree Celsius Degree Kelvin Rankine or Reaumur The formulae for conversion is as follows; You will create a main file which will call any one of the 4 functions. The name of the function files that you will create are as follows; F2C, F2K, F2Ra and F2Re where the actual calculation of the selected conversion will be computed. Each of the function files will have temperature in Fahrenheit as the input argument and the corresponding conversion as its output argument The program is to run as many times as the user wishes. At the end of the program display an output statement which has the user input (temperature) and the corresponding conversion.

Explanation / Answer

FahrenheitConverter.java

package org.students;

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

public class FahrenheitConverter {

   public static void main(String[] args) {
       System.out.println(":: This Program will convert the temperature from Fahrenheit into Celsius(C),Kelvin(K),Rankine(Ra),Reaumur(Re) ::");
       System.out.println(" ");
       Scanner sc = new Scanner(System.in);
       // To format the output
       DecimalFormat df = new DecimalFormat("#.##");
       while (true) {
           System.out.print("Enter the temperature (In Fahrenheit): ");
           // Getting the temperature value from the user.
           double ftemp = sc.nextDouble();
           // calling the functions
           double ctemp = F2C(ftemp);
           double ktemp = F2K(ftemp);
           double ratemp = F2Ra(ftemp);
           double retemp = F2Re(ftemp);
           System.out.println(" ");
           // Displaying the Results
           System.out.println(ftemp + " Fahrenheit(F) to " + df.format(ctemp)
                   + " Celsius(C)");
           System.out.println(ftemp + " Fahrenheit(F) to " + df.format(ktemp)
                   + " Kelvin(K)");
           System.out.println(ftemp + " Fahrenheit(F) to " + df.format(ratemp)
                   + " Rankine(Ra)");
           System.out.println(ftemp + " Fahrenheit(F) to " + df.format(retemp)
                   + " Reaumur(Re)");
           System.out.println(" ");
           // The process wil continue of the user press 'Y' or 'y'.Exit if the
           // press 'N' or 'n'
           System.out.print("Do you want to continue(Y/N) ::");
           char ch = sc.next(".").charAt(0);
           if (ch == 'Y' || ch == 'y')
               continue;
           else {
               System.out.println(":: Program Exit ::");
           }
           break;
       }

   }

   // Method which will convert temperature from Fahrenheit to Reaumur
   private static double F2Re(double ftemp) {
       double retemp = (ftemp - 32) / 2.25;
       return retemp;
   }

   // Method which will convert temperature from Fahrenheit to Rankine
   private static double F2Ra(double ftemp) {
       double ratemp = ftemp + 459.67;
       return ratemp;
   }

   // Method which will convert temperature from Fahrenheit to Kelvin
   private static double F2K(double ftemp) {

       double ktemp = (ftemp + 459.6) / 1.8;
       return ktemp;
   }

   // Method which will convert temperature from Fahrenheit to celsius
   private static double F2C(double ftemp) {
       double ctemp = (ftemp - 32) / 1.8;
       return ctemp;

   }

}

__________________________________________________________________________________________

output:

:: This Program will convert the temperature from Fahrenheit into Celsius(C),Kelvin(K),Rankine(Ra),Reaumur(Re) ::

Enter the temperature (In Fahrenheit): 45

45.0 Fahrenheit(F) to 7.22 Celsius(C)
45.0 Fahrenheit(F) to 280.33 Kelvin(K)
45.0 Fahrenheit(F) to 504.67 Rankine(Ra)
45.0 Fahrenheit(F) to 5.78 Reaumur(Re)

Do you want to continue(Y/N) ::y
Enter the temperature (In Fahrenheit): 60

60.0 Fahrenheit(F) to 15.56 Celsius(C)
60.0 Fahrenheit(F) to 288.67 Kelvin(K)
60.0 Fahrenheit(F) to 519.67 Rankine(Ra)
60.0 Fahrenheit(F) to 12.44 Reaumur(Re)

Do you want to continue(Y/N) ::y
Enter the temperature (In Fahrenheit): 50

50.0 Fahrenheit(F) to 10 Celsius(C)
50.0 Fahrenheit(F) to 283.11 Kelvin(K)
50.0 Fahrenheit(F) to 509.67 Rankine(Ra)
50.0 Fahrenheit(F) to 8 Reaumur(Re)

Do you want to continue(Y/N) ::n
:: Program Exit ::

_________________________________________________________________________________________