Practice

<aside> 💡 Note: Assume all methods that you write are public static.

</aside>

Average

Code a method called average that takes two double parameters, a and b. The method should return the average of the two doubles. Test if your average method works in the main method by calling it at least 3 times with different arguments and printing the results. Bonus points if you write a JavaDoc comment for the average method.

💻 Template code

✅ Solution code

Temperature

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 + 32 Celsius = (5.0 / 9) * (Fahrenheit – 32)

Bonus points for writing JavaDoc comments for both methods.

Write a test program that asks the user for a temperature in Fahrenheit and prints out the Celsius conversion. Then ask the user for a temperature in Celsius and print out the Fahrenheit conversion.

Adapted from Exercise 6.8, Introduction to Java Programming (Comprehensive), 10th ed. by Y. Daniel Liang