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

import java.util.Scanner; public class Temparature_conversion { private static v

ID: 3805765 • Letter: I

Question

import java.util.Scanner;
public class Temparature_conversion
{
private static void celsius_to_fahrenheit() // called function
{
Scanner scan = new Scanner(System.in);
Double celsius = scan.nextDouble(); // Take celsius temparature
System.out.println(celsius + " celsius equivalent fahrenheit temparature is " + ((celsius * 9 / 5.0) + 32)+" fahrenheit");
convertTemperature(); // temparature conversion
}
private static void fahrenheit_to_celsius() // // called function
{
Scanner scan = new Scanner(System.in);
Double fahrenheit = scan.nextDouble(); // Take fahrenheit temparature
System.out.println(fahrenheit + " fahrenheit equivalent celsius temparature is " + ((fahrenheit - 32) * (5 / 9.0))+" celsius");
convertTemperature(); // temaparature conversion
}
public static void main(String[] args) // main function
{
convertTemperature(); // Calling function
}
private static void convertTemperature()
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter 1 for fahrenheit to Celsius" + " Enter 2 for Celsius to fahrenheit"+" Enter other than 1 or 2 to Exit." + " Enter your choice : ");
int selection = scan.nextInt(); // accept selection
if(selection == 1) // if statement for fahrenheit to Celsius conversion
{
System.out.println("Enter temparature in fahrenheit:");
fahrenheit_to_celsius();
}
else if (selection == 2) // if statement for Celsius to fahrenheit conversion
{
System.out.println("Enter a temparature in Celsius:");
celsius_to_fahrenheit();
}
else
{
System.out.println("Stop converting");
}
}
}

I need the output to be as this: 75 in Fahrenheit is 23.88888888888889 in Celsius. 23.88888888888889 in Celsius is 75 in Fahrenheit. when I run the program please.

Explanation / Answer

Please use longValue() to remove the precision for the double value. Below program will give you the desired output. import java.util.Scanner; public class Temparature_conversion { private static void celsius_to_fahrenheit() // called function { Scanner scan = new Scanner(System.in); Double celsius = scan.nextDouble(); // Take celsius temparature Double result= ((celsius * 9 / 5.0) + 32); System.out.println(celsius + " celsius equivalent fahrenheit temparature is " + result.longValue()+" fahrenheit"); convertTemperature(); // temparature conversion } private static void fahrenheit_to_celsius() // // called function { Scanner scan = new Scanner(System.in); Double fahrenheit = scan.nextDouble(); // Take fahrenheit temparature System.out.println(fahrenheit.longValue() + " fahrenheit equivalent celsius temparature is " + ((fahrenheit - 32) * (5 / 9.0))+" celsius"); convertTemperature(); // temaparature conversion } public static void main(String[] args) // main function { convertTemperature(); // Calling function } private static void convertTemperature() { Scanner scan = new Scanner(System.in); System.out.print("Enter 1 for fahrenheit to Celsius" + " Enter 2 for Celsius to fahrenheit"+" Enter other than 1 or 2 to Exit." + " Enter your choice : "); int selection = scan.nextInt(); // accept selection if(selection == 1) // if statement for fahrenheit to Celsius conversion { System.out.println("Enter temparature in fahrenheit:"); fahrenheit_to_celsius(); } else if (selection == 2) // if statement for Celsius to fahrenheit conversion { System.out.println("Enter a temparature in Celsius:"); celsius_to_fahrenheit(); } else { System.out.println("Stop converting"); } } }