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

Write a method that will convert the supplied number from Celcius to Fahrenheit

ID: 2247491 • Letter: W

Question

Write a method that will convert the supplied number from Celcius to Fahrenheit or from Fahrenheit to Celcius depending on whether the variable toMetric is true If it is then convert from imperial to metric else convert from metric to imperial. T compositefunction c = (T compositefunction F - 32) imes5/9 and T compositefunction F = T compositefunction cimes 9/5 + 32 convertTemp(68, true) rightarrow 20 convertTemp(22, false) rightarrow 71.6 For example: Test System.out.println(convertTemp(97.0, true)): Result 36.1.1

Explanation / Answer

Below is your program: -

ConvertTemp.java

public class ConvertTemp {

public static double convertTemp(double num, boolean toMetric) {

double res = 0;

if (toMetric) {

res = (num - 32) * 5.0 / 9.0;

} else {

res = ((num * 9.0) / 5.0) + 32;

}

res = Math.round(res * 100) / 100.0;

return res;

}

public static void main(String[] args) {

System.out.println(convertTemp(97.0, true));

System.out.println(convertTemp(68, true));

System.out.println(convertTemp(22, false));

}

}

Output: -

36.11
20.0
71.6

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote