Results 1 to 5 of 5
- 03-04-2009, 11:42 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 1
- Rep Power
- 0
Help with fahrenheit to celsius conversion
Hi.I have recently been given the task of creating a program that converts a Fahrenheit temp to a Celsius temp with the calculateCelsius() method. The formula for the conversion is :
Celsius = (5/9) * (Fahrenheit -32)
public static float calculateCelsius(float f)
This is what I have so far, and take it easy on me I'm lost to say the least.
import javax.swing.*;
public class FahrenheitToCelsius {
public static void main (String[] args) {
// Add code to prompt user to enter a Fahrenheit temperature
// add code to invoke the method calculateCelsius and to
// display the results here.
}
public static float calculateCelsius(float f) {
return 0.0f; // so incomplete file will compile
// change the return statement to return the
// calculated Celsius value.
}
}
I'm having trouble with how to obtain the users Fahrenheit temp input and use the entered value with the supplied calculation and return an answer in another dialog box.
Your help is much appreciated!!
Thanks
- 03-04-2009, 11:45 PM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
i have minimal experience with gui's, but seems like you need to learn them, specifically swing. here's a tutorial: Trail: Creating a GUI with JFC/Swing (The Java™ Tutorials)
-
Or are you in fact supposed to create a GUI? If you are this new to programming, my guess is that the instructor wants you to create a program that uses a console input and output. If so, look into using a java.util.Scanner object and get your input via the Scanner.
- 03-06-2009, 09:30 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
something along these lines may help get you started.
if it needs to be a method just create a method which does the calculateions called "farToCelsius()" and call it by saying "result = farToCelsius(far, celsius)
hope that helps a bitJava Code:package ...package name.......; import java util.Scanner; public class .............class name.......; { public static void main(String[] args) { float celsius, fahr; int lower, upper, step; Scanner scan = new Scanner(System.in); System.out.println("Enter farenheit: "); fahr = scan.nextInt(); celsius = (5.0/9.0)*(fahr-32.0); System.out.println("Farenheit is: " + fahr); System.out.println("Celsius is: " + celsius); fahr = fahr + step; }
- 03-07-2009, 11:11 AM #5
Member
- Join Date
- Sep 2008
- Posts
- 43
- Rep Power
- 0
Similar Threads
-
Doc to Pdf conversion
By praveen.kb in forum Advanced JavaReplies: 2Last Post: 01-16-2009, 12:27 PM -
Fahrenheit to celsius
By lalithalydia in forum New To JavaReplies: 3Last Post: 02-05-2008, 07:50 AM -
farenheit to celsius
By lalithalydia in forum New To JavaReplies: 2Last Post: 02-02-2008, 08:44 AM -
Celsius Converter project
By jpdamigaman in forum NetBeansReplies: 3Last Post: 11-14-2007, 12:20 AM -
Converts from Fahrenheit to Celsius
By trill in forum New To JavaReplies: 1Last Post: 08-06-2007, 05:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks