my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Celsius to Fahrenheit converter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Celsius to Fahrenheit converter" Watch "Celsius to Fahrenheit converter" New topic
Author

Celsius to Fahrenheit converter

Gretchen Peters
Greenhorn

Joined: Feb 19, 2002
Posts: 2
Help! I am a java beginner and my homework is due tonight!
I am reading Beginning Java 2 by Ivor Horton. So far, I have done one program "Hello World."
For tonight, I have to create a temperature converter that converts C to F and F to C.
"This program should consist of a single class. You should include within the main function the necessary logic to translate 212 F to its equivalent Celsius value, and 100 C to its equivalent Fahrenheit value."
The formula for converting F to C is: C=5/9(F-32)
The formula for converting C to F is: F=9/5C+32.
Any suggestions?
TIA!
Javagrrl
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
Note: Someone is going to give you a hard time about not following the Naming Policy here at Java Ranch.
The good news is that your assignment is very easy. Do you have any specific questions - aspects of the program that are causing confusion? What do you have so far?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
javagrrl,
Please read the JavaRanch Naming Policy. . . oh yeah - what Dirk said!
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Wow - that was the fastest change in history!!!
Gretchen Peters
Greenhorn

Joined: Feb 19, 2002
Posts: 2
Okay okay I changed my name.
All I know is what I learned in "Hello, World!"
public class TempConverter {
public static void main(String [] args){
double F=212.0;
double C;
C=5/9(F-32);
System.out.println ("C=" +C);
}
}
TIA.
Gretchen
[ February 19, 2002: Message edited by: Gretchen Peters ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
What time zone?
To satisfy the requirement of:

"This program should consist of a single class. You should include within the main function the necessary logic to translate 212 F to its equivalent Celsius value, and 100 C to its equivalent Fahrenheit value."

you're already half way there. After following Jim's advice, just add a line to convert some arbitrary degree in Celsius to Fahrenheit (and output everything if you'd like - be careful about "extra features" though - my experience has been that some professors will take points off for "extra features" not explicitly required in the program description). Is your program supposed to take any user inputs (command line or other)? It doesn't seem that this is a requirement.
[ February 19, 2002: Message edited by: Dirk Schreckmann ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Mmmm... thin mints...
What you have looks pretty close. I assume you're getting a compiler error just before the print statement? In Java (and every other computer language I know of), to represent multiplication you need to use the * sign. It isn't enough to write the symbols next to one another as you would in algebra - something like "6x" needs to be rewritten as "6 * x".
The Fahrenheit part should be simple once you've got the formula for Celsius working. Good luck...


"I'm not back." - Bill Harding, Twister
 
wood burning stoves
 
subject: Celsius to Fahrenheit converter
 
Similar Threads
Conversion question
Which is the best practice?
java temperature converter
program with the dreaded for loop
Exception error? Please help, frustrating