5 Replies - 753 Views - Last Post: 15 November 2010 - 05:56 AM Rate Topic: -----

#1 pipwax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-May 09

Temperature Conversion

Posted 14 November 2010 - 08:26 AM

// Description: This program gets a string from a dialog box.
// File:   dialogInputOutput/ThirdProgram.java
// Author: Michael Maus
// Date:   29 Jan 2005

import javax.swing.*;

public class temp {

    public static void main(String[] args) {
        String temp;  // A local variable to hold the name.
        Object conversion = (5.0 / 9.0) (temp - 32);
        temp = JOptionPane.showInputDialog(null, "enter a Temperature Here");

        JOptionPane.showMessageDialog(null, "The Temperature you entered of, " + temp \n "Celsius" + conversion);
    }

}




I need help with this code not sure what I am doing wrong. Any help would be greatly appreciated.

This post has been edited by g00se: 14 November 2010 - 08:36 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Temperature Conversion

#2 skyzer  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 25
  • Joined: 05-September 10

Re: Temperature Conversion

Posted 14 November 2010 - 08:42 AM

hi.
does it give any errors? what is the ouput?

your temp variable is of type String, you need to parse it as integer or double before you could do the calculations.
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,262
  • Joined: 27-December 08

Re: Temperature Conversion

Posted 14 November 2010 - 08:48 AM

You also need to get input before you use temp. In addition, better to assign the result to a double rather than an Object. No need for an Object variable here at all.
Was This Post Helpful? 0
  • +
  • -

#4 pipwax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-May 09

Re: Temperature Conversion

Posted 14 November 2010 - 08:58 AM

View Postskyzer, on 14 November 2010 - 07:42 AM, said:

hi.
does it give any errors? what is the ouput?

your temp variable is of type String, you need to parse it as integer or double before you could do the calculations.


This is the error message
====================================error==============================
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The left-hand side of an assignment must be a variable
Syntax error on token ")", AssignmentOperator expected after this token
Syntax error on tokens, delete these tokens

at temp.main(temp.java:13)
==========================end error=====================================

Sill new with java I don't understand everything
Thanks

View Postmacosxnerd101, on 14 November 2010 - 07:48 AM, said:

You also need to get input before you use temp. In addition, better to assign the result to a double rather than an Object. No need for an Object variable here at all.

Sorry I will take not of this in the future.

View Postmacosxnerd101, on 14 November 2010 - 07:48 AM, said:

You also need to get input before you use temp. In addition, better to assign the result to a double rather than an Object. No need for an Object variable here at all.

Sorry I will take not of this in the future.
Was This Post Helpful? 0
  • +
  • -

#5 pipwax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-May 09

Re: Temperature Conversion

Posted 14 November 2010 - 12:14 PM

View Postpipwax, on 14 November 2010 - 07:26 AM, said:

// Description: This program gets a string from a dialog box.
// File:   dialogInputOutput/ThirdProgram.java
// Author: Michael Maus
// Date:   29 Jan 2005

import javax.swing.*;

public class temp {

    public static void main(String[] args) {
        String temp;  // A local variable to hold the name.
        Object conversion = (5.0 / 9.0) (temp - 32);
        temp = JOptionPane.showInputDialog(null, "enter a Temperature Here");

        JOptionPane.showMessageDialog(null, "The Temperature you entered of, " + temp \n "Celsius" + conversion);
    }

}




I need help with this code not sure what I am doing wrong. Any help would be greatly appreciated.


Okay I have working code. However, it is not making the calculations any ideas?
import javax.swing.*;
public class FahrenheitToCelsiusb {
	public static void main(String[] args) {
		String fahrenheit1;
	    double fahrenheit = 98; //Say 100;
		double celsius = (5.0 / 9) * (fahrenheit - 32);

		fahrenheit1 = JOptionPane.showInputDialog(null, "Enter Nummber");
		
		JOptionPane.showMessageDialog(null, "your tempature," + celsius );
	}
	
}




Edited by macosxnerd101: Please use code tags! Like so: :code:.
Was This Post Helpful? 0
  • +
  • -

#6 skyzer  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 25
  • Joined: 05-September 10

Re: Temperature Conversion

Posted 15 November 2010 - 05:56 AM

your fahrenheit1 variable is of type string, you can't do calculations on that.
you have to use parseDouble method for that.

and this line
double celsius = (5.0 / 9) * (fahrenheit - 32);

won't work correctly if it's before assigning to variable by input dialog

try googling for "fahrenheit to celsius java".
there will be alot of examples which will lead you to correct path
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1