Just started a Java class and the first HW assingment was issued.
I have read the chapter a million times and cant figure out what the heck am I doing wrong. The assingment is supposed change Celcius temperature to Fahrenheit using a worker class.

import javax.swing.*;


public class ConvertTemperature {

   public static void main(String[] args) {
     // Get the  Celcius Temperature
     String getCelcius = JOptionPane.showInputDialog("Enter Celcius");
     double celcius = Double.parseDouble(getCelcius);
     // Create a CelciusToFahrenheit object that stores the celcius temperature.
     CelciusToFahrenheit you = new CelciusToFahrenheit(celcius);

     // Display Farenheight temperature.
     JOptionPane.showMessageDialog( null, you.surroundCelciusToFahreheit());
}
  }

***************************************************
 class CelciusToFahrenheit {

   private double fahrenheit;

   public CelciusToFahrenheit (double celcius ) {
      double fahrenheit;
      fahrenheit = 1.8 * celcius + 32;
   }

   public double surroundConvertTemperature() {
      return fahrenheit;

   }
}

Someone PLEASE help! before I crack........ :cry:

You should really use code brackets when pasting code, it makes it a lot easier to read.

I had to make two changes to make that work, the first was changing the line...

//  The function surroundCelciusToFahreheit doesn't even exist.
 JOptionPane.showMessageDialog( null, you.surroundCelciusToFahreheit());

To.

JOptionPane.showMessageDialog( null, you.surroundConvertTemperature());

The next one isn't so obvious. You had declared a local variable by the same name of a member variable in the CelciusToFahrenheit class constructor. Don't do that, because anything you do with the variable declared locally will only change the local variable, and not the data member. So just remove the following line from that constructor...

double fahrenheit;

And after that it should work fine.

-Fredric

That did the trick! Thanks for the tip dude, it saved me a lot of headaches... :cheesy:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.