In java Se8 i am trying to write a program convert temperature between celsius, fahrenheit and kelvin, but i am stuck at how to return the proper result without chage the frame, and I cnould not figure out how to use those three settemp method.
code:
//Define class
public class Temperature
{
//Declare array
public static String[] scales={"Celsius","Fahrenheit","Kelvin"};
//Declare variables
private String scale;
private double temp;
private char Scale;
//Define constructor
public Temperature(double temp)
{
//Set value
this.temp =temp;
}
//Define constructor
public Temperature(double temp,String scale)
{
//Set value
this.temp=getTemp();
//Set value
this.Scale=getScale();
}
//Define method
public char getScale()
{
//Return
return Scale;
}
//Define method
public void setScale(String scale)
{
if(scale.equals("C")||scale.equals("F")
||scale.equals("K")||scale.equals("Celsius")
||scale.equals("Fahrenheit")||
scale.equals("Kelvin"))
{
this.Scale=scale.charAt(0);
}
}
//Define method
public double getTemp()
{
return temp;
}
//Define method
public void setTemp(double temp)
{
this.temp=temp;
}
//Define method
public void setTemp(double temp,char scale)
{
if (scale == 'K')
{
this.temp = temp + 273;
}
else if (scale == 'C')
{
this.temp = temp;
}
else if (scale == 'F')
{
this.temp = ((9 * temp) / 5 ) + 32;
}
}
//Define method
public void setTemp(double temp,String scale)
{
if(scale.equals("Celsius"))
{
this.temp=this.temp;
}
else if (scale.equals("Fahrenheit"))
{
this.temp = ((9 * temp) / 5 ) + 32;
}
else if (scale.equals("Kelvin"))
{
this.temp = temp + 273;
}
}
//Define method
public String toString()
{
return ""+this.getTemp()+this.getScale();
}
//Define main
public static void main(String[] args)
{
Temperature t = new Temperature(10.1);
t.setScale("C");
System.out.println("C");
System.out.println(t); // 10.1C;
t.setScale("F");
t.setTemp(10.1,'F');
System.out.println(t);//50.18F;
System.out.println("10.1F");
System.out.println("F");
t.setScale("Kelvin");
t.setTemp(10.1,"Kelvin");
System.out.println(t.getTemp()+"K");//283.25;
System.out.println("10.1K");
t.setScale("F");
t.setTemp(10.1,'F');
System.out.println(t);//50.18F;
System.out.println("10.1F");
t.setScale("K");
t.setTemp(10.1,'K');
System.out.println(t);//50.18F;
System.out.println("10.1K");
}
}
In java Se8 i am trying to write a program convert temperature between celsius, fahrenheit and...
Using the latest version of Java JDK, Create a version of this TempConverter program to convert from Fahrenheit to Kelvin. Read the Fahrenheit temperature from the user. public class TempConverter { //----------------------------------------------------------------- // Computes the Fahrenheit equivalent of a specific Celsius // value using the formula F = (9/5)C + 32. //----------------------------------------------------------------- public static void main (String[] args) { final intBASE = 32; final double CONVERSION_FACTOR = 9.0 / 5.0; double fahrenheitTemp; intcelsiusTemp= 24; // value to convert fahrenheitTemp= celsiusTemp*...
FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...
Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...
import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //ask the user for a temperature System.out.println("Enter a temperature:"); double temp = scnr.nextDouble(); //ask the user for the scale of the temperature System.out.println("Is that Fahrenheit (F) or Celsius (C)?"); char choice = scnr.next().charAt(0); if(choice == 'F') { //convert to Celsius if given temperature was Fahrenheit System.out.println(temp + " degrees Fahrenheit is " + ((5.0/9) * (temp-32)) + " degrees Celsius"); } else {...
Java program Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating- point number for the temperature and a character for the scale, eitherでfor Celsius or 'F' for fahrenheit. The class should have Four constructors: one for the number of degrees, one for the scale, one for both the degrees and scale, and a default constructor. For each of these constructors, assume zero degrees if no value is specified and celsius if no...
Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...
Question: Fahrenheit To Celsius Temperature Converter GUI Assignment Write A GUI To... java Fahrenholt to Celsius Temperature Converter GUI Assignment Write a Gul to convert Fahrenheit temperatures to Celsius temperatures and has the following appearance: Com Convert It must include the following foatures • The frame we must say 'Fahrenheit to Celsius Temperature Converter • A border layout will be used for the GUI • The JLabelite of the GUI wil suy Fahrerholt to Celsius Temperature Converter and be in...
Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....
C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have 2 Labels (each one of them assigned only to Celsius and Fahrenheit), 2 TextBoxes (each one of them assigned only to Celsius and Fahrenheit), only 1 Convert Button, 1 Clear Button, and 1 Exit Button. Also, 1 Error message label which will display the error messages. The application should only allow the user to enter the desired temperature just in one of the TextBoxes...
C# I am having trouble this program. So far my temperature converter program is converting temps from C to F. However, whenever I try to convert F to C, it's keep crashing and displaying an error message, which I can not figure it out and do not know how to fix it. Attached are two screenshots are of message. Do you know what is causing the issue? I would much appreciate your assistance. namespace Temp Conv { public partial class...