Download the attached .java file. Run it, become familiar with its processes. Your task is to turn TemperatureConversion into GUI based program. it should, at the least, perform similar functions as their text output versions. The key factor to remember is that the workings should remain the same (some tweaks may be necessary) between text and GUI programs, while the means pf visual presentation and user interaction changes. You must properly document, comment, indent, space, and structure both programs. import java.util.*;
Please add comments to code
public class TemperatureConversionSelection { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); double degrees, // user input convertedDegrees; // calculated output char units; // user input: 'F' or 'f' for Fahrenheit // or 'C' or 'c' for Celsius System.out.println();//Blank lines for readability System.out.println(); System.out.println ("Enter a temperature in degress (for example 29.6): "); degrees = keyboard.nextDouble(); System.out.println(); System.out.println ("Enter 'F' (or 'f') for Fahrenheit or " + "'C' (or 'c') for Celsius: "); units = keyboard.next().charAt(0); System.out.println(); switch(units) { case 'F': case 'f': convertedDegrees = 5 * (degrees -32)/9; System.out.println(degrees + " degrees F = " + convertedDegrees + " degrees Celsius."); break; case 'C': case 'c': convertedDegrees = degrees * 9/5 + 32; System.out.println(degrees + " degrees C = " + convertedDegrees + " degrees Fahrenheit."); break; default: System.out.println("Unknown units -"); System.out.println(" cannot do calculation -"); System.out.println(" next time enter either " + "'F' for Fahrenheit or 'C' for Celsius."); } //end switch } }
import java.util.Scanner;
public class TemperatureConversionSelection {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double degrees; // user input values
double convertedDegrees; // calculated output valus
char units; // user input: 'F' or 'f' for Fahrenheit,// or 'C' or
'c' for Celsius
System.out.println();//Blank lines for readability
System.out.println();
System.out.println("Enter a temperature in degress (for example
29.6): ");
degrees = keyboard.nextDouble();
System.out.println();
System.out.println("Enter 'F' (or 'f') for Fahrenheit or "+ "'C'
(or 'c') for Celsius: ");
units = keyboard.next().charAt(0);
System.out.println();
switch(units) {
case 'F':
case 'f':convertedDegrees = 5 * (degrees -32)/9;
System.out.println(degrees + " degrees F = " + convertedDegrees + "
degrees Celsius.");
break;
case 'C':
case 'c': convertedDegrees = degrees * 9/5 + 32;
System.out.println(degrees + " degrees C = "+ convertedDegrees + "
degrees Fahrenheit.");
break;
default:System.out.println("Unknown units -");
System.out.println(" cannot do calculation -");
System.out.println(" next time enter either "+ "'F' for Fahrenheit
or 'C' for Celsius.");
} //end switch
}
}
Test case:
Input:
Enter a temperature in degress :- 29.5
Enter for Fahrenheit for Celsius:- 15
Output:
Unknown units -
cannot do calculation -
next time enter either 'F' for Fahrenheit or 'C' for Celsius.
Hint points:
1.Convert Fahrenheit into Celsius.
celsius = (fahrenheit-32)*5)/9;
ex:fahrenheit =15,celsius=-9.4452
2.Convert Celsius into Fahrenheit .
Fahrenheit =(9*celsius/5)*32;
Get Answers For Free
Most questions answered within 1 hours.