944,208 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1699
  • Java RSS
Aug 18th, 2005
0

Java novice PLEASE HELP!!!

Expand Post »
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:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
splifficus is offline Offline
2 posts
since Aug 2005
Aug 18th, 2005
0

Re: Java novice PLEASE HELP!!!

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

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

To.

Java Syntax (Toggle Plain Text)
  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...

Java Syntax (Toggle Plain Text)
  1. double fahrenheit;

And after that it should work fine.

-Fredric
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Daishi is offline Offline
80 posts
since Aug 2005
Aug 19th, 2005
0

Re: Java novice PLEASE HELP!!!

That did the trick! Thanks for the tip dude, it saved me a lot of headaches... :cheesy:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
splifficus is offline Offline
2 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Java BankAccount program
Next Thread in Java Forum Timeline: Object to File





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC