Write a Temperature class. the class will have three conversion methods: toCelsi
ID: 3689188 • Letter: W
Question
Write a Temperature class. the class will have three conversion
methods: toCelsius(), toKelvin(), and toFahrenheit(). These methods
will return a temperature in those three scales equal to the this
temperature. Note that the value of this is not changed in these
conversions. In addition to these three conversion methods the
class will have methods add(Temperature), subtract(Temperature),
multiply(Temperature), divide(double). these four methods all
return a Temperature equaled to the respective operation. Note that
the this value is not changed in these operations. Two Boolean
methods equals(Temperature), and greatThan(Temperature) will return
true if the this is greater than the parameter. Your class should
include a read() method and a toString() method. Remember methods
add, subtract, multiply, divide and the three conversion methods
all return a Temperature. Include at least two constructors: a
default constructor and an explicit constructor. YOU MUST USE A
PRIVATE HELPER METHOD CALLED SET() THAT TAKES THE PARAMETERS OF THE
CONSTRUCTOR AND TESTS FOR APPROPIATE VALUES FOR EACH POSSIBLE
SCALE. This private set() method can be used to guarantee
Temperature values are in proper range. the subtract() and divide()
methods can call the constructor to return a Temperature in a legal
range. a switch statement should be used throughout this class when
choosing between "C", "F" and "K". Absolute zero for kelvin is 0,
for Fahrenheit -459.67, and for celcius is -273.15. your program
must guarantee this absolute value is not violated. for the
EQUALS() method consider changing the this Temperature and the
parameter Temperature to the same scale and then testing the degree
value for equality. create 3 array of random sizes of 1-5 elements
-------------------------------------------------------------------------------------------------
here is the demo:
public class TemperatureDemo {
public static final int ARRAY_SIZE = 5;
public static void main(String[] args) {
int x;
Temperature temp1 = new Temperature(120.0, 'C');
Temperature temp2 = new Temperature(100, 'C');
Temperature temp3 = new Temperature(50.0, 'C');
Temperature temp4 = new Temperature(232.0, 'K');
Temperature tempAve = new Temperature(0.0, 'C');
Temperature[] tempArray = new Temperature[ARRAY_SIZE];// create pointer
// to array
Temperature t1;
for (x = 0; x < tempArray.length; x++) {
t1 = new Temperature();
tempArray[x] = t1;// fill the array with Temperatures
}
System.out.println("Temp1 is " + temp1);
// temp1 = temp1.toKelvin();
temp2.toKelvin();
System.out.println("Temp1 to Kalvin is " + temp1);
if (temp1.equals(temp3)) {
System.out.println("These two temperatures are equal");
} else {
System.out.println("These two temperature are not equal");
}
System.out.println("Temp1 is " + temp1);
System.out.println("Temp2 is " + temp2);
System.out.println("Temp3 is " + temp3);
System.out.println("Temp4 is " + temp4);
tempAve = tempAve.add(temp1);
tempAve = tempAve.add(temp2);
tempAve = tempAve.add(temp3);
tempAve = tempAve.add(temp4);
tempAve = tempAve.divide(4);
System.out.println("the average temperatrure is " + tempAve);
Temperature[] temperatureArrayOne;
Temperature[] temperatureArrayTwo;
Temperature[] temperatureArrayThree;
temperatureArrayOne = new Temperature[getRandomArraySize()];
readTemperatureArray(temperatureArrayOne);
printTemperatureArray(temperatureArrayOne);
t1 = getAverage(temperatureArrayOne);
System.out.println("the average of temperature array one is " + t1);
temperatureArrayTwo = new Temperature[getRandomArraySize()];
readTemperatureArray(temperatureArrayTwo);
printTemperatureArray(temperatureArrayTwo);
t1 = getAverage(temperatureArrayTwo);
System.out.println("the average of temperature array two is " + t1);
temperatureArrayThree = new Temperature[getRandomArraySize()];
readTemperatureArray(temperatureArrayThree);
printTemperatureArray(temperatureArrayThree);
t1 = getAverage(temperatureArrayThree);
System.out.println("the average of temperature array three is " + t1);
Temperature[] largest = getLargestArray(temperatureArrayOne, temperatureArrayTwo, temperatureArrayThree);
Temperature[] arrayWithLargestValues;
if (temperatureArrayOne == largest)
arrayWithLargestValues = createArrayWithLargestValues(largest, temperatureArrayTwo, temperatureArrayThree);
else if (temperatureArrayTwo == largest)
arrayWithLargestValues = createArrayWithLargestValues(largest, temperatureArrayOne, temperatureArrayThree);
else// fractionArrayThree is largest
arrayWithLargestValues = createArrayWithLargestValues(largest, temperatureArrayOne, temperatureArrayTwo);
System.out.println("An array with the largest values from the 3 arrays is");
printTemperatureArray(arrayWithLargestValues);
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
here is how output should look like
thank you