Question

In: Computer Science

**********Java language************ 1-      (Conversions between Celsius and Fahrenheit) Write a class that contains the following two methods:...

**********Java language************

1-      (Conversions between Celsius and Fahrenheit) Write a class that contains the following two methods:

/** Convert from Celsius to Fahrenheit */

public static double celsiusToFahrenheit(double celsius)

/** Convert from Fahrenheit to Celsius */

public static double fahrenheitToCelsius(double fahrenheit)

The formula for the conversion is:

Celsius = (5.0 / 9) * (Fahrenheit – 32)

Fahrenheit = (9.0 / 5) * Celsius + 32

Program output should be like:

If you want to convert from Fahrenheit To Celsius press 0 vice versa press 1:

0

Enter the degree in Fahrenheit: 22

The degree in Celsius: -5.5

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

If you want to convert from Fahrenheit To Celsius press 0 vice versa press 1:

1

Enter the degree in Celsius: 33

The degree in Celsius: 91.4

Solutions

Expert Solution

import java.util.Scanner;
class Main
{
/** Convert from Celsius to Fahrenheit */
public static double celsiusToFahrenheit(double celsius)
{
return (9.0/5)*celsius+32;
}
/** Convert from Fahrenheit to Celsius */
public static double fahrenheitToCelsius(double fahrenheit)
{
return (5.0/9)*(fahrenheit-32);
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("If you want to convert from Fahrenheit To Celsius press 0 vice versa press 1:");
int ch = sc.nextInt();
if(ch==0)
{
System.out.print("Enter the degree in Fahrenheit: ");
double temp = sc.nextDouble();
double result = fahrenheitToCelsius(temp);
System.out.print("The degree in Celsius: "+result);
}
else
{
System.out.print("Enter the degree in Celsius: ");
double temp = sc.nextDouble();
double result = celsiusToFahrenheit(temp);
System.out.print("The degree in Fahrenheit: "+result);
}
}
}


Related Solutions

Write a class called VLPUtility with the following static methods: Java Language 1. concatStrings that will...
Write a class called VLPUtility with the following static methods: Java Language 1. concatStrings that will accept a variable length parameter list of Strings and concatenate them into one string with a space in between and return it. 2. Overload this method with two parameters, one is a boolean named upper and one is a variable length parameter list of Strings. If upper is true, return a combined string with spaces in upper case; otherwise, return the combined string as...
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents....
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents.  The formula for converting a temperature from Celsius to Fahrenheit is F = 9/ 5 C + 32 where F → Fahrenheit temperature C → Celsius temperature.  Allow the user to enter the range of temperatures in Celsius to be converted into Fahrenheit.  Your program must use a loop to display the values of the temperature conversions (see sample output). Sample...
in java Write a program that convert a Fahrenheit to Celsius. For conversion, use as many...
in java Write a program that convert a Fahrenheit to Celsius. For conversion, use as many as methods you want
Write a simple java class that contains the following three methods: 1. isosceles -- accepts 3...
Write a simple java class that contains the following three methods: 1. isosceles -- accepts 3 integers which represent the sides of a triangle. Returns true if the triangle is isosceles and false otherwise. 2. perimeter - accepts 3 integers that represent the sides of a triangle and returns the perimeter of the triangle. 3. area -- accepts 3 integers, which represent the sides of a triangle and calculates and returns the area of the triangle. Hint: use Heron's formula....
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in...
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in Celsius and the program Coverts the input to Fahrenheit using the following formula T(°F) = T(°C) × 1.8 + 32 submit the source code Design output Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings...
A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings representing the names of staff members. The constructor takes an ArrayList of String names as a parameter. In addition to the constructor, you need to implement the following methods The methods 1. public boolean equals(Staff other) - Determines if the other Staff contains all the same elements in the same order as this Staff 2. public boolean sameContents(Staff other) - Determines if the other...
Java Language The int t contains an integer between 1 and 50 (inclusive). Write code that...
Java Language The int t contains an integer between 1 and 50 (inclusive). Write code that outputs the number in words and stores the result in the String inwords. For example, if t is 35 then inwords should contain "thirty five". Test Cases Test case #1 Expected result: When t is 2, your code sets inwords to "two" Test case #2 Expected result: When t is 50, your code sets inwords to "fifty" Test case #3 Expected result: When t...
Write a Temperature class that will hold a temperature in Fahrenheit, and provide methods to get...
Write a Temperature class that will hold a temperature in Fahrenheit, and provide methods to get the temperature in Fahrenheit, Celsius and Kelvin. The class should have the following field: ftemp – A double that hold a Fahrenheit temperature. The class should have the following methods: Constructor – The constructor accepts a Fahrenheit temperature (as a double) and stores it in the ftemp field. setFahrenheit – The setFahrenheit method accepts a Fahrenheit temperature (as a double) and stores it in...
In java beginner coding language ,Write a class called Sphere that contains instance data that represents...
In java beginner coding language ,Write a class called Sphere that contains instance data that represents the sphere’s diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter methods for the diameter. Include methods that calculate and return the volume and surface area of the sphere. Include a toString method that returns a one-line description of the sphere. Create a driver class called MultiSphere, whose main method instantiates and updates several Sphere objects.
*In C++ language please* Create a table that converts temperatures from Celsius to Fahrenheit Ask the...
*In C++ language please* Create a table that converts temperatures from Celsius to Fahrenheit Ask the user if they would like to know today's temperatures When "yes": Ask or their name -Generate a random number: use the length of their name (nameLngth) to set the seed Use the length of their name (nameLngth) as the starting point, and 99 as the ending point for a range of Celsius temperatures Output the range of Celsius temperatures alongside the Fahrenheit temperature conversions...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT