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

write a Java program that asks the user for a temperature (in either degrees Cel

ID: 3684738 • Letter: W

Question

write a Java program that asks the user for a temperature (in either degrees Celsius or degrees Fahrenheit). If the user entered Celsius, you will convert the temperature to Fahrenheit. If they entered Fahrenheit, you will convert the temperature to Celsius. Here is how to convert between temperature systems (be sure to not use integer division in Java so you can keep the decimal of something like 5/9): F = (9/5)*C + 32 C = (5/9)*(F-3This program should contain a single class (called Proj2) with a main method. Your program should compile and run in BlueJ. Here are some additional requirements:

-Your program should work correctly with either upper- or lower-case letters (C/c/F/f)

-You should print an error if the user enters a character other than C/c/F/f

- You should round temperatures to the nearest two decimal places

. You should round temperatures to the nearest two decimal places Here is an example of how to round to two decimal places: //Do this at the very top of the file import java.text.* //Do this once at the beginning of main Decimal Format df = new DecimalFormat("#0.00"); //Suppose you want to print val rounded to the nearest two decimal places double val = 3.278514; System.out.println(df.format(val)); Here is how to get a single character from user input: //Do this at the very top of the file import java.util.* //Do this once at the beginning of main Scanner s -new Scanner(System.in); //This prompts the user for a single character and reads it into letter System.out.print("Enter letter:" char 1etter = (S.nextLine()).charAt(0);

Explanation / Answer

// The below program should for your requirements.

import java.util.*;
import java.text.*;


public class HelloWorld
{
public static void main(String a[])
{
Scanner inp=new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#0.00");

System.out.println("Enter temparature in Farenheit or Celcius");
double it,ot;
char s;
it=inp.nextDouble();
s=inp.next().charAt(0);
if( s=='C'||s=='c')
{
ot=9.0/5.0*it+32.0;
System.out.println("The corresponding Farenheit values is :");
System.out.println(df.format(ot));
}
else if(s=='F'||s=='f')
{
ot=5.0/9.0*(it-32);
System.out.println("The corresponding Farenheit values is :");
System.out.println(df.format(ot));
}
else
System.out.println("Error");
}
}