| | |
Java novice PLEASE HELP!!!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2005
Posts: 2
Reputation:
Solved Threads: 0
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:
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:
•
•
Join Date: Aug 2005
Posts: 80
Reputation:
Solved Threads: 2
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...
To.
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...
And after that it should work fine.
-Fredric
I had to make two changes to make that work, the first was changing the line...
Java Syntax (Toggle Plain Text)
// The function surroundCelciusToFahreheit doesn't even exist. JOptionPane.showMessageDialog( null, you.surroundCelciusToFahreheit());
To.
Java Syntax (Toggle Plain Text)
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...
Java Syntax (Toggle Plain Text)
double fahrenheit;
And after that it should work fine.
-Fredric
![]() |
Similar Threads
- C++ Vs Java (C++)
- Chat program (Java)
- Help Java novice (Java)
- Java Help!!! (Java)
- Java Expert (Needed) (Java)
Other Threads in the Java Forum
- Previous Thread: Java BankAccount program
- Next Thread: Object to File
Views: 1504 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addball addressbook android api append apple applet application arguments array arrays automation binary bluetooth button chat class classes client code component css csv database draw eclipse ee error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaarraylist javaprojects jmf jni jpanel julia jvm key linux list loan loop map method methods mobile netbeans newbie number object oracle output packets phone print problem program programming project recursion reporting robot scanner screen se server service set size sms socket software sort sql stream string swing test threads time transfer tree ubuntu windows wrong





