Results 1 to 3 of 3
Thread: Celsius to Fahrenheit
- 09-30-2010, 04:35 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 83
- Rep Power
- 0
Celsius to Fahrenheit
so my first assignment is to convert celsius to fahrenheit and I think that I got eveything right, except my last taks is to
Write a main method for the previous class Temperature that creates an object of that type and then calls its methods, outputting the result on the console.
I did that but the input is already set to 100 and just outputs the values in the console window. Is there a really quick way just to ask the user for an input in fahrenheit and output in console window in both fahrenheit and celsius and vice versa???
public class Temperature
//Converts between Celsius and Fahrenheit and outputs the conversion
{
private double celsius;
private double fahrenheit;
//converts from celsius to fahrenheit and stores in variables
public void setCelsius(double temp){
fahrenheit = 9.0/5.0*temp + 32;
celsius = temp;
}
//converts from fahrenheit to celsius and stores in variable
public void setFahrenheit(double temp){
celsius = (temp-32) * 5.0/9.0;
fahrenheit = temp;
}
//prints the temperature in celsius in the console
public void outputCelsius(){
System.out.println("The temperature is " + celsius + "C");
}
//prints the temperature in fahrenheit in the console
public void outputFahrenheit(){
System.out.println("The temperature is " + fahrenheit + "F");
}
//Creating an object that will output the temperature on the cosnole window
public static void main(String[] args) {
Temperature t = new Temperature();
t.setCelsius(100);
t.outputFahrenheit();
t.outputCelsius();
}
}
- 09-30-2010, 04:44 AM #2
Member
- Join Date
- Sep 2010
- Posts
- 21
- Rep Power
- 0
For input, check the the class Scanner and for output you alread have System.out to show your results on your console !
- 09-30-2010, 04:50 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 83
- Rep Power
- 0
Similar Threads
-
Fahrenheit to Celcius program error
By bosoxfan in forum New To JavaReplies: 3Last Post: 02-10-2010, 03:38 AM -
Help with fahrenheit to celsius conversion
By java_is_killingme in forum New To JavaReplies: 4Last Post: 03-07-2009, 11:11 AM -
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 -
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