a temperature class that has two instance variables: a temperature value double and a character for the scale, either c for Celsius or F for Fahrenheit. The classe should have four constructor methods: one for each instance variable(assume zero degrees if no value is specified and Celsius if no scale is specified). One with two parameter for the two instance variable, and a no-argument constructor. include the following (10 two accessor methods to return the temperature- one to return the degree of Celsius, the other to return the degree Fahrenheit – use the this fomula to write the two methods and round to nearest tenth of a degree:
DegreeC= 5(degree-32)/9
degree=(9(degree)/5)+32;
2. three mutator methods: one to set the value, one to set the scale( F or C) and one to set both ;
3. three comparison methods, and equals method to test whether two temperature are equal, one method to test whether one temperature is greater than another
Do anyone know how to write this program in java programing? i some help for out line?
Don sir, you need som experts experience from http://expert.userstyle.com/
Reply:Temperature Conversion Program in Java
Here's a simple program to convert temperatures between degrees Celcius, Fahrenheit and Kelvin written in Java. There's no GUI used here - all output is done via the command line.
File: Converter.java
/**
* Conversion between temperatures in Celcius, Fahrenheit and Kelvin
* Uses conversion forumulas from the wikipedia:
* http://en.wikipedia.org/wiki/Temperature...
* User: Elaine
* Date: 27-Dec-2005
*/
public class Converter {
public Converter()
{
}
// Method to convert from degrees Celcius to degrees Fahrenheit
public static float celciusToFahrenheit(float degCelcius)
{
float degFahrenheit;
degFahrenheit = degCelcius * 9/5 + 32;
return degFahrenheit;
}
// Method to convert from degrees Fahrenheit to degrees Celcius
public static float fahrenheitToCelcius(float degFahrenheit)
{
float degCelcius;
degCelcius = (degFahrenheit - 32) * 5/9;
return degCelcius;
}
// Method to convert from degrees Celcius to degrees Kelvin
public static float celciusToKelvin(float degCelcius)
{
float degKelvin;
degKelvin = degCelcius + 273.15f;
return degKelvin;
}
// Method to convert from degrees Kelvin to degrees Celcius
public static float kelvinToCelcius(float degKelvin)
{
float degCelcius;
degCelcius = degKelvin - 273.15f;
return degCelcius;
}
// Main method demonstrating usage of above methods
public static void main(String[] args)
{
System.out.print("100 degrees Celcius in Fahrenheit is: ");
System.out.println(celciusToFahrenheit(1...
System.out.print("-40 degrees Fahrenheit in Celcius is: ");
System.out.println(fahrenheitToCelcius(-...
System.out.print("0 degrees Celcius in Kelvin is: ");
System.out.println(celciusToKelvin(0));
// to convert from Kelvin to Fahrenheit, combine two methods:
System.out.print("373.15 degrees Kelvin in Fahrenheit is: ");
System.out.println(celciusToFahrenheit(k...
}
}
Luv
SK
Mail me :funmansk (at) yahoo.com
Join my group: http://groups.yahoo.com/group/funmansk
My blog : http://firstcitizen.wordpress.com
Fun blog : http://funmansk.blogspot.com
Get paid to view ad: http://www.advercash.net/index.php?ref=f...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment