Not Getting Correct Output In Fahrenheit To Centigrade Conversion?
Mar 6, 2014
I am writing a small program to convert temperature from Fahrenheit to Centigrade. I cannot figure out why I keep getting 0.00 for the Centigrade temperature output. Also, I cannot figure out how to get the F degree symbol before or after the temp. I know in JOptionPane the char = 176 is the code for it but im not sure how to code it into the program. My program keeps saying 0.00 for Centigrade temp on the output ....
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class tempConversion {
public static void main(String[] args) {
String newDecimal;
[Code] .....
Okay I figured out the Degree symbol!(String DEGREE = "u00b0") phew... now only if i can get the correct output!
I have followed the instructions carefully but the conversion values are not correct.
Write a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. The formula for converting a temperature from Celsius to Fahrenheit is F - | C + 32 where ¥ is the Fahrenheit temperature and C is the Celsius temperature. Your program must use a loop to display the table.
Code
public class TempConversion { public static void main(String[] args) { for(double i = 0; i <= 20.0; i++) {
Every time I input a number for fahrenheit, I always get 273.15. Everything compiles, the only problem is that run-time error. I need getting fahrenheit to exactly change to kelvin.
//my class public class TempConversion { private double fahrenheit; public TempConversion() { fahrenheit = 0;
<import javax.swing.JOptionPane; public class TempCalc {
public static void main(String[] args) {
//Confirming which conversion to compute. String FarOrCel = (JOptionPane.showInputDialog("Would you like to calculate a Farenheit value or a Celsius value? (Enter Farenheit or Celsius)");
[Code] ....
So I've been trying to come up with a Farenheit to Celsius converter and back. However, whenever I run the program in JCreator it never recognizes the string "Farenheit". Even if I put that exact thing (I copy/pasted from the if (FarOrCel == "Farenheit")) it keeps asking me for a Celsius value.
[quote name='INNOCENTREAPER##!' date='28 September 2014 - 07:40 PM' timestamp='1411958437' post='2057072']
<import javax.swing.JOptionPane; public class TempCalc { public static void main(String[] args) {
//Confirming which conversion to compute. String FarOrCel = JOptionPane.showInputDialog("Would you like to calculate a Farenheit value or a Celsius value? (Enter Farenheit or Celsius)";
The assignment reads: Develop a Java program (F2C.java) for converting a temperature from the Fahrenheit to the Celsius scale. The program will read the temperature graphically using an input dialog box
(JOptionPane.showInputDialog) and will show also the result graphically on a message dialog box (JOptionPane.showMessageDialog).
I can get my input box to show, but I am unable to get to the output box
What I have came up with:
import javax.swing.JOptionPane; public class F2C { public static void main(String[] args) { // Enter Farenheit String Fahrenheit = JOptionPane.showInputDialog(
I am trying to sum up the elements of an array. When I test my code the sum is always off by one. For example if I input: 20, 40,30 it gives me 89 instead of 90.
This is what I have so far:
public static void main(String[args]){ int size = kbd.nextInt(); int [] myArray = new int [size] //user inputs the elements of array for(int i =0; i<myArray.length; i++){ myArray[i]= kbd.nextInt(); } int total = sumNum(myArray,0, myArray.length-1) System.out.println("The sum is"+ total); }
What it is supposed to do is decide whether a ceiling fan is on or off, and describe it (color, area, speed). This is all user input (even pi) so it should decide whether to turn it on or off but for some reason skips over my if/else if statements all together.
I've tried changing it around a bit, looking up what my problem may be but this problem remains the same. my code:
import java.util.Scanner; public class CeilingFan { final int slow = 1; final int medium = 2; final int fast = 3; private int speed; boolean on = false; private double radius = 5; private double pi = 3.1415; String color = "blue";
Why is my program not calculating the total and average of the price of the items and not printing it out?
Java Code: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package assignment4;
[code]...
It prints out everything but the total of the items and I dont know why. :(
Write a CiUI application that converts Celsius temperatures to Fahrenheit temperatures. The user should be able to enter a Celsius temperature, click a button, and then sec the equivalent Flhnfflhelt temperature. Use the following formula to make the conversion: F - - y C + 32..F is the Fahrenheit temperature and C is the Celsius temperature.
Now the program runs (In Jgrasp) But when I Enter a number in the fahrenheit box and hit "COnvert' NOTHING happens. I went over my code and I can't find what seems to be the problem...I tried changing
ActionListener Listener = new ConvertListener(); convertBtn.addActionListener(ConvertListener); <----- I tried changing ConvertListener to just Listener but it gives me more problems import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField;
I am trying to teach myself a bit of java and came across the following line of code in the degrees to Fahrenheit converter tutorial:
int tempFahr = (int)((Double.parseDouble(tempTextField.getText()) )
* 1.8 + 32);
I know what the code does in that it is getting the value that the user has input in text field tempTextField and is applying the mathematical calculation to convert to Fahrenheit and assigning the result to the variable tempFahr.
I am guessing any value input into a text box is considered a string?I am guessing that Double.parseDouble takes in a string and converts it to a double.I am assuming that by simply putting (int) in front of
that it calculates the value and converts it to an int?The tutorial says this example is not localizable because the parseDouble method is not localizable - what does it mean by localizable?
I'm new to coding and we have an assignment for class to convert fahrenheit to celsius so far this is what i have:
import java.util.Scanner; public class Lab5 { public static void main(String[] args) { //variable dec Scanner scan = new Scanner(System.in); double input;
[code]...
This is what he wants us to do "Write a method name celsius that accepts a Fahrenheit temperature as an argument. The method should return the temperature, converted to Celsius. Demonstrate the method by asking the user a temperature value to convert. Then below the result, call a loop that displays a table of the Fahrenheit temperatures 0 through 20 and their Celsius equivalents."
I am new to java and I am trying to learn a little about GUI. I found this problem of creating a converter for temp from farenheit to celcius. I have everything working, except for when I hit the converter button... it does not convert.
I was asked to work on building a program that can convert Fahrenheit to kelvin. Need to create a for loop that spits out the value of kelvin for every degree increase from 32 degrees Fahrenheit to 100 degrees Fahrenheit.
I am new to Java, programming, and intelliJ. I am trying to make a BMI Calculator using this code as my initial template which converts Fahrenheit to Celsius.
import javax.swing.JFrame; public class Fahrenheit { //----------------------------------------------------------------- // Creates and displays the temperature converter GUI. //-----------------------------------------------------------------
[code]....
I created a local field within BMIButtonListener for weight, height, resultLabel, and was able to compile but it did not calculate and listed exceptions.
Write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20 and convert to farenheit.
I have to use doubles for Celsius and Fahrenheit and in the formula. I get a runtime error with the following displayed:
I will display a table of temperatures in their Celsius and Farenheit equivalents.
celsiusfarenheit
import java.util.*; import java.lang.*; import java.io.*; class TemperatureConversion { public static void main (String[] args) throws java.lang.Exception { double celsius;// Temperature in degrees Celsius minimum double farenheit;// Temperature in degrees Fahrenheit
I am trying to create a java file that will print out the temperature in Fahrenheit. This is my code.
import java.util.Scanner; public class TemperatureConverter { public static void main(String[] args) { float temperature; Scanner in= new Scanner(System.in); System.out.printf("Enter temperature in degrees Celsius: "); temperature = in.nextInt(); //Getting a red X next to this line. fahrenheit = temperature * 9/5 +32; //Add this line System.out.printf(+temperature + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit."); //System.out.println(temp1 + " degrees celsius is " + fahrenheit + " degrees Fahrenheit."); } }
I need to know what I am doing wrong. Using Eclipse as my platform. I have entered comments where I am getting red X's.
The error I get when I run the program.
Exception in thread "main" java.lang.Error: Unresolved compilation problems: fahrenheit cannot be resolved to a variable fahrenheit cannot be resolved to a variable at TemperatureConverter.main(TemperatureConverter.jav a:24)
I am trying to write a program converting Fahrenheit to Celsius using a for loop. I get it to run and Fahrenheit goes to a hundred. My issue is that the Celsius just says 100 down the column and is not converting. I have tried messing with it, and can not figure what is wrong with it.
import java.util.Scanner; public class Controlstatement { public static void main(String[] args) { double F = 1.0; double Celcius = 100; System.out.printf("%s%20s", "Farenheit", "Celcius" ); for (int Farenheit = 0; Farenheit <= 100; Farenheit++) { F = Celcius * (Farenheit - 32 * 5.0/9.0); System.out.printf("%4d%,20.2f", Farenheit, Celcius); } } }
I’m trying to write a program in Java that will take the input of a temperature in Fahrenheit and convert it to Celsius and Kelvin. This is what I have so far but when I run the program on Eclipse it says the temp. in Celsius is infinity and the same for kelvin. Why is it not preforming the operation and spiting out the correct numbers?
import java.util.Scanner; public class Temperature { public static void main(String[] args) { // This program converts temperatures from Fahrenheit to Celsius to Kelvin. double temperature1;// operands double temperature2; double temperature3;
I've made a simple program in Java (Eclipse) that converts Fahrenheit to Celsius.The class is:
Java Code: package ehu.student; public class ConversorTemperaturas { /*--------------------------------------------------------------*/ /*Clase que dado una temperatura en Fahrenheit la canvierte en C*/ /*--------------------------------------------------------------*/ public float farenheit2celsius (float d){ float celsius, aux;
[code]...
When I write t.farenheit2celsius(25.6), appears the following error: "The method farenheit2celsisus(float) in the type ConversorTemperaturas is not applicable for the arguments (double)"If i change in the class the type float for double there is not problem. Why can't i use the type float?
I need to do a conversion of Celsius to Fahrenheit and viceversa using methods and a for loop. The methods are public static double celsiustoFahrenheit (double celsius) and public static double Fahrenheittocelsius (double fahrenheit). It gives me weird numbers and i have to have some format that you can see attached ....
package temperatureconverter; import java.util.Scanner; public class TemperatureConverter { public static void main(String[] args) { Scanner corvette = new Scanner(System.in); System.out.printf("%12s%12s","Celsius","Fahrenheit");
How to write a program which will automatically correct the parts of speech of a document.
Example: say in my document I have My/PRONOUN name/PRONOUN is/VERB Jhon/NOUN. He/PRONOUN is/VERB going/ADJ to/PREPOSITION school/NOUN
Now I need to change My/PRONOUN name/NOUN is/VERB Jhon/NOUN. He/PRONOUN is/VERB going/VERB to/PREPOSITION school/NOUN...How to do using java. The document may contain 100 lines tagged with parts of speech.
Netbeans tells me it's an illegal start of expression during the initialisation of the interactWithUser method. public class InvertLetter {
/** * @param args the command line arguments */ public static void main(String[] args) { /** * String mit den Kleinbuchstaben. */ final String lowercase = "abcdefghijklmnopqrstuvwxyz";
I have a simple WORKING Factorial program code but I don't understand how it works.Here is code snippet
public class Factorial{ public static void main(String[] args){ long limit = 5; //long factorial = 1;
[code]....
My question is - every time in a given FOR loop if Factorial value (highlighted and bold above) is initialized / reset to "long factorial = 1" then how does code produces correct values? Because correct values can be produced only if interim factorial results are saved/stored and used next time to multiply with "factor" value.
Here instead of retaining it, we initialize or reset to 1 so every time you multiply by 1 and it should produce 1! = 1, 2! = 2, 3! = 3, 4! = 4 etc which would be an incorrect result.
I want to use the bit of code below to re-write the page to tell the user of a successful registration and then redirect them to another page. My problem is that I can't figure out how to get the path right for the login page. As can see, my first choice was to have the use click to the login page and when I use href it works fine.
I tried to use the entire file page starting at C and that didn't work. I also tried
${pageContext.request.contextPath}/Login
which is what I had to do for the action in the form for the login servlet page.
My question is what is the URL I need to use. By the way, if I jut put in google's URL, or any other for that matter, it works fine.
I'm trying to figure out the correct way to replace number into letter. In this case, I need two steps.
First, convert letter to number. Second, restore number to word.
Words list: a = 1, b = 2, f = 6 and k = 11.
I have word: "baafk"
So, for first step, it must be: "211611"
Number "211611" must be converted to "baafk".
But, I failed at second step.
Code I've tried:
public class str_number { public static void main(String[] args){ String word = "baafk"; String number = word.replace("a", "1").replace("b","2").replace("f","6").replace("k","11"); System.out.println(word);
[Code] .....
Result for converting to number: baafk = 211611 But, result for converting above number to letter: 211611 = bkfk
What do I miss here?
How to distinguish if 11 is for "aa" and for "k"? D