d. In line 154, add a comment indicating that the method will convert from fahre
ID: 3533425 • Letter: D
Question
d. In line 154, add a comment indicating that the method will convert from fahrenheit to Celsius and in line 155, add the method header for this method. The method will be called convertToCelsius. this method returns a value of type double and takes an argument of type double. Name the double parameter degree. In line 156, add a left brace to begin the body of the method. In line 157, add a return statement that performs the conversion calculation. To do this, follow the return keyword with the following expression:
( 5.0 / 9.0 ) * ( degree - 32.0 );
In line 159, add the right brace to end the body of the method. follow the brace with a comment indicating the end of this method. Leave line 158 blank for readability.
e. You will now invoke the convertToFahrenheit method and store the result in variable convertedDegree, to be displayed in outputJTextField. In line 115, replace 0.00 with a call to method convertToFahrenheit. Pass variable degreeCelsius to the convertToFahrenheit method. Variable degreeCelsius contains the degrees entered by user, converted to a double (lines 111-112).
f. You will now invoke the convertToCelsius method and store the result in variable convertedDegree, to be displayed in outputJTextField. In line 137, replace 0.00 with a call to the convertToCelsius method. Pass variable degreeFahrenheit to the convertToCelsius method. Variable degreeFahrenheit contains the degrees entered by user, converted to a double (lines 133-134).
Btw, can you please do this line by line as stated in the instructions so I can better understand it. Example, line 159: .........
Also, this java program is done in a slightly different format. Example.....
private void convertCelsiusJButtonActionPerformed(
ActionEvent event )
{
// format temperature value
DecimalFormat temperature = new DecimalFormat( "0.00" );
// retrieve input from user
double degreeFahrenheit = Double.parseDouble(
degreesJTextField.getText() );
Explanation / Answer
here is the program to convert temperatures in celcius to fahreinheit and vice versa
#include <iostream>
using namespace std;
int main()
{
int ftemp;
int ctemp;
int select = 0;
cout << "Please select from the following: " << endl;
cout << "1) Fahrenheit-to-Celsius" << endl;
cout << "2) Celsius-to-Fahrenheit" << endl << endl;
cout << "Enter: ";
cin >> select;
if (select == 1)
{
cout << " Enter temperature in Fahrenheit to convert to degrees Celsius: ";
cin >> ftemp;
ctemp = (ftemp-32) * 5 / 9;
cout << "Equivalent in Celsius is: " << ctemp << endl;
}
else if (select == 2)
{
cout <<" Enter temperature in Celsius to convert to degrees Fahrenheit: ";
cin >> ctemp;
ftemp = ctemp*9/5 + 32;
cout << "Equivalent in Fahrenheit is: " << ftemp << endl;
}
else
cout << "Valid options 1 or 2." << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.