So my teacher wants us to write the following program:
"2. Write a Temperature class that has two instance variables: a temperature value ( a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degree if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no argument constructor (set to Zero degree Celsius). Include the following: (1) two get methods to return the temperature one to return the degrees Celsius, the other to return the degrees Fahrenheit -use the following formulas to write the two methods, and round to the nearest tenth of a degree:
degreeC = 5(degreeF – 32)/9
degreeF = (9(degreeC)/5) + 32
(2) three comparison methods: an equals method to test whether two temperatures are equal, one method to test whether one temperature is grater than another, and one method to test whether one temperature is less than another( note that a Celsius temperature can be equal to a Fahrenheit temperature as indicated by the above formulas). Then write a driver program (or Programs) that tests all the methods. Be sure to use each of the constructors, to include at least one true and one false case for each of the comparison methods, and to test at last the following temperature equalities: 0.0 degree C=32.0 degrees F, -40.0 degrees C = -40.0 degree F, and 100.0 degree C=121.0 degree F."
She said that I only need two instance variables, a double temperature value,
and a String a = " ";
But then she requests that I write methods that compare two values of temperature, the methods would figure out if they were equal, larger or smaller then each other. She then requests that we use a test class to use each of these methods. I am extremely confused on how I should orientate the main class, as well as how to call the methods in the test class.
"2. Write a Temperature class that has two instance variables: a temperature value ( a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degree if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no argument constructor (set to Zero degree Celsius). Include the following: (1) two get methods to return the temperature one to return the degrees Celsius, the other to return the degrees Fahrenheit -use the following formulas to write the two methods, and round to the nearest tenth of a degree:
degreeC = 5(degreeF – 32)/9
degreeF = (9(degreeC)/5) + 32
(2) three comparison methods: an equals method to test whether two temperatures are equal, one method to test whether one temperature is grater than another, and one method to test whether one temperature is less than another( note that a Celsius temperature can be equal to a Fahrenheit temperature as indicated by the above formulas). Then write a driver program (or Programs) that tests all the methods. Be sure to use each of the constructors, to include at least one true and one false case for each of the comparison methods, and to test at last the following temperature equalities: 0.0 degree C=32.0 degrees F, -40.0 degrees C = -40.0 degree F, and 100.0 degree C=121.0 degree F."
She said that I only need two instance variables, a double temperature value,
and a String a = " ";
But then she requests that I write methods that compare two values of temperature, the methods would figure out if they were equal, larger or smaller then each other. She then requests that we use a test class to use each of these methods. I am extremely confused on how I should orientate the main class, as well as how to call the methods in the test class.
Comment