Java novice PLEASE HELP!!!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2005
Posts: 2
Reputation: splifficus is an unknown quantity at this point 
Solved Threads: 0
splifficus splifficus is offline Offline
Newbie Poster

Java novice PLEASE HELP!!!

 
0
  #1
Aug 18th, 2005
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:
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 80
Reputation: Daishi is an unknown quantity at this point 
Solved Threads: 2
Daishi Daishi is offline Offline
Junior Poster in Training

Re: Java novice PLEASE HELP!!!

 
0
  #2
Aug 18th, 2005
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...

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

To.

  1. 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...

  1. double fahrenheit;

And after that it should work fine.

-Fredric
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 2
Reputation: splifficus is an unknown quantity at this point 
Solved Threads: 0
splifficus splifficus is offline Offline
Newbie Poster

Re: Java novice PLEASE HELP!!!

 
0
  #3
Aug 19th, 2005
That did the trick! Thanks for the tip dude, it saved me a lot of headaches... :cheesy:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 1504 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC