Need JAVA code for this question: Ratings will be given to the user with answer,
ID: 3751359 • Letter: N
Question
Need JAVA code for this question:
Ratings will be given to the user with answer, Thank you!
Explanation / Answer
CelsiusToFahInToCmDegToRad.java
import java.util.Scanner;
public class CelsiusToFahInToCmDegToRad {
public static void main(String[] args) {
//Declaring variables
int choice;
double celsius, fahrenheit, inches, cms, degrees, radians;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//displaying the menu
System.out.println("1.it will convert celsius temperature to its corresponding Fahrenheit temperature.");
System.out.println("2.it will convert a distance of inches to its corresponding value in centimeters.");
System.out.println("3.it will convert an angle measurement from degrees to radians.");
//getting the choice entered by the user
System.out.print("Enter Choice :");
choice = sc.nextInt();
//If the user enters invalid choice display error message
if (choice < 1 || choice > 3) {
System.out.println("Incorrect entry,please enter 1,2 or 3");
choice = sc.nextInt();
}
//Based on the user choice the corresponding case will be executed
if (choice == 1) {
//Getting the input entered by the user
System.out.println("Enter temperature in celsius (C):");
celsius = sc.nextDouble();
//Displaying the output
System.out.printf("%.2f C is %.2f F ", celsius, celsiusToFahrenheit(celsius));
} else if (choice == 2) {
//Getting the input entered by the user
System.out.println("Enter distance in inches (in):");
inches = sc.nextDouble();
//Displaying the output
System.out.printf("%.2f inches is %.2f cms ", inches, inchesToCms(inches));
} else if (choice == 3) {
//Getting the input entered by the user
System.out.println("Enter angle in degrees :");
degrees = sc.nextDouble();
//Displaying the output
System.out.printf("%.2f degrees is %.2f radians ", degrees, degreesToRadians(degrees));
}
}
//This method will convert degrees to radians
private static double degreesToRadians(double degrees) {
return (degrees * 3.14159) / 180;
}
//This method will convert inches to centimeters
private static double inchesToCms(double inches) {
return inches * 2.54;
}
//This method will convert celsius to fahrenheit
private static double celsiusToFahrenheit(double celsius) {
return (((9.0 / 5.0) * celsius) + 32.0);
}
}
__________________
Output#1:
1.it will convert celsius temperature to its corresponding Fahrenheit temperature.
2.it will convert a distance of inches to its corresponding value in centimeters.
3.it will convert an angle measurement from degrees to radians.
Enter Choice :4
Incorrect entry,please enter 1,2 or 3
1
Enter temperature in celsius (C):
45
45.00 C is 113.00 F
_______________
Output#2:
1.it will convert celsius temperature to its corresponding Fahrenheit temperature.
2.it will convert a distance of inches to its corresponding value in centimeters.
3.it will convert an angle measurement from degrees to radians.
Enter Choice :2
Enter distance in inches (in):
45.5
45.50 inches is 115.57 cms
______________
Output#3:
1.it will convert celsius temperature to its corresponding Fahrenheit temperature.
2.it will convert a distance of inches to its corresponding value in centimeters.
3.it will convert an angle measurement from degrees to radians.
Enter Choice :3
Enter angle in degrees :
45
45.00 degrees is 0.79 radians
________Could you plz rate me well.Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.