Code is written, but not working.

Reply

Join Date: Sep 2004
Posts: 6
Reputation: Maverick is an unknown quantity at this point 
Solved Threads: 0
Maverick Maverick is offline Offline
Newbie Poster

Code is written, but not working.

 
0
  #1
Sep 21st, 2004
ok the error is that it doesnt recognize the package class.

  1.  
  2.  
  3. package celsiustofahrenheit;
  4.  
  5. public class CelsiusToFahrenheit {
  6. public static void main(String args [])
  7. {
  8. double celsius, fahrenheit = 0;
  9. System.out.println("\n\tEnter temperature in celsius: ");
  10. celsius = MyInput.readDouble();
  11.  
  12. fahrenheit = 1.8 * celsius + 32;
  13.  
  14. system.out.println("\n\tThat is " + fahrenheit + " degrees fahrenheit.");
  15. }
  16. }

is there another way to get around the "package" stuff.. like are there other classes ( I THINK they're called classes, such a newb -- sorry) such as java.io.*; or something that can be put in place of the package stuff?

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 84
Reputation: jerbo is an unknown quantity at this point 
Solved Threads: 1
jerbo jerbo is offline Offline
Junior Poster in Training

Re: Code is written, but not working. HELP PLEASE

 
0
  #2
Sep 21st, 2004
This implies you have a folder/directory called 'celsiustofahrenheit' and it contains your 'CelsiusToFahrenheit.java' file in it.

Packages organize classes into a hierarchy of related subsystems. In Java classes are placed in specific directories called packages.

A quick solution is you should be able to remove the package line from your source (for simplistic one classs applications.) Packages are best used when you have an application that is calling many support classes.

For example, you may have a file structure like:
com\yourname\convert
com\yourname\converters

Your main application/class (call it 'Convert.java') may reside in 'com\yourname\convert' and would contain a
package com.yourname.convert;
line. If you then call a class called 'CelsiusToFahrenheit.class' which resides in the 'com\yourname\converters' folder, you would then include (in the 'Convert.java' source,) an
import com.yourname.converters.*;
line. This is so the compiler can find the 'CelsiusToFahrenheit.class'.

Of course your 'CelsiusToFahrenheit.java' source has a
package com.yourname.converters;
line
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 6
Reputation: Maverick is an unknown quantity at this point 
Solved Threads: 0
Maverick Maverick is offline Offline
Newbie Poster

Re: Code is written, but not working. HELP PLEASE

 
0
  #3
Sep 21st, 2004
Awesome!! ok, thank you. I fixed that problem quick. I just have one left. When i compile it it tells me this:

"C:\Documents and Settings\Booth\My Documents\java_programs\Ch3Ex9.java:13: cannot resolve symbol
symbol : variable MyInput
location: class Ch3Ex9
celsius = MyInput.readDouble();
^
1 error

Tool completed with exit code 1"
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 84
Reputation: jerbo is an unknown quantity at this point 
Solved Threads: 1
jerbo jerbo is offline Offline
Junior Poster in Training

Re: Code is written, but not working. HELP PLEASE

 
0
  #4
Sep 21st, 2004
According to your code snippet above, you need a class called MyInput with a readDouble method. I did not see this in your code above. I would assume you may have an additional java file called MyInput.java?? If so it will need to be in the same folder as the 'CelsiusToFahrenheit.java' code. (unless you figured out my rambelings about packages above.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

Re: Code is written, but not working.

 
0
  #5
Sep 24th, 2004
Originally Posted by Maverick
ok the error is that it doesnt recognize the package class.

  1.  
  2.  
  3. package celsiustofahrenheit;
  4.  
  5. public class CelsiusToFahrenheit {
  6. public static void main(String args [])
  7. {
  8. double celsius, fahrenheit = 0;
  9. System.out.println("\n\tEnter temperature in celsius: ");
  10. celsius = MyInput.readDouble();
  11.  
  12. fahrenheit = 1.8 * celsius + 32;
  13.  
  14. system.out.println("\n\tThat is " + fahrenheit + " degrees fahrenheit.");
  15. }
  16. }

is there another way to get around the "package" stuff.. like are there other classes ( I THINK they're called classes, such a newb -- sorry) such as java.io.*; or something that can be put in place of the package stuff?

Thanks.
//*********************************************
Hi!
Your code is OK, but I think the program has problem whit
"celsius = MyInput.readDouble();"
I used another package and your program was OK.
bye
Peter
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
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC