Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Temperature class. create 3 array of random sizes of 1-5 elements ------

ID: 3788232 • Letter: W

Question

Write a Temperature class. 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); } }

Explanation / Answer

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);
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote