Reference no: EM132170643
Using JAVA
Write a class called Temperature that has two instance variables: a temp value (a floating-point number - data type double) and a character for the scale, either ‘C' for Celsius or ‘F' for Fahrenheit. The class should have a constructor that sets each instance variable (assume zero degrees if no temp value is specified and Celsius if no scale is specified), and it should include the following methods:
1. two accessor methods: one to return the degrees Celsius and the other to return the degrees Fahrenheit- use the following formulas to write the two methods: DegreesC = 5(degreesF - 32)/9 DegreesF = (9(degreesC)/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. a comparison method: it should return -1 if the invoking temperature is less than the argument temperature, 0 if they are equal and 1 if the invoking temperature is greater than the argument one;
4. a toString method: returns a String representing the calling Temperature object. The numeric value of the temperature should be rounded to the nearest tenth of a degree. For example, System.out.println(new Temperature(98.164555, F)); //should print: 98.2 F
Then write a driver program called TempTester that tests all the methods from the Temperature class. Example tests: 0.0 degrees C = 32.0 degrees F, -40.0 degrees C = -40.0 degrees F, and 100.0 degrees C = 212.0 degrees F.