Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Celsius to Fahrenheit converter

 
Gretchen Peters
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javagrrl,
Please read the JavaRanch Naming Policy. . . oh yeah - what Dirk said!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow - that was the fastest change in history!!!
 
Gretchen Peters
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic