Try the fastest way to create flashcards
Question

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:

fahrenheit=(9.0/5)celsius+32fahrenheit = (9.0 / 5) * celsius + 32

celsius=(5.0/9)(fahrenheit32)celsius = (5.0 / 9) * (fahrenheit – 32)

Write a test program that invokes these methods to display the following tables:

Celsius     Fahrenheit      |   Fahrenheit      Celsius
40.0        104.0           |   120.0           48.89
39.0        102.2           |   110.0           43.33
...
32.0        89.6            |   40.0            4.44
31.0        87.8            |   30.0            -1.11

Solution

Verified
Answered 2 years ago
Answered 2 years ago
Step 1
1 of 4

To convert from Celsius to Fahrenheit we use the first provided formula.

public static double celsiusToFahrenheit(double celsius){
  // Calculate fahrenheit using formula
  double fahrenheit = (9.0 / 5) * celsius + 32;
  return fahrenheit;
}

Create a free account to view solutions

Create a free account to view solutions

Recommended textbook solutions

Intro to Java Programming, Comprehensive Version 10th Edition by Y. Daniel Liang

Intro to Java Programming, Comprehensive Version

10th EditionISBN: 9780133761313Y. Daniel Liang
1,628 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
961 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions
Introduction to Algorithms 4th Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions

More related questions

1/4

1/7