Question: Driver: public class TemperatureDemoWithArrays { public static void main(String[] args) { int x; Temperature average; System.out.println(You will be asked to fill 3 randomly sized arrays.);

Driver:

public class TemperatureDemoWithArrays { public static void main(String[] args) { int x; Temperature average; System.out.println("You will be asked to fill 3 randomly sized arrays."); Temperature[] temperatureArrayOne; Temperature[] temperatureArrayTwo; Temperature[] temperatureArrayThree; temperatureArrayOne = new Temperature[getRandomArraySize()]; readTemperatureArray(temperatureArrayOne); System.out.println("The values of temperature array one are "); printTemperatureArray(temperatureArrayOne); average = getAverage(temperatureArrayOne); System.out.println("The average of temperature array one is " + average); temperatureArrayTwo = new Temperature[getRandomArraySize()]; readTemperatureArray(temperatureArrayTwo); System.out.println("The values of temperature array two are "); printTemperatureArray(temperatureArrayTwo); average = getAverage(temperatureArrayTwo); System.out.println("The average of temperature array two is " + average); temperatureArrayThree = new Temperature[getRandomArraySize()]; readTemperatureArray(temperatureArrayThree); System.out.println("The values of temperature array three are "); printTemperatureArray(temperatureArrayThree); average = getAverage(temperatureArrayThree); System.out.println("The average of temperature array three is " + average); Temperature[] largest = getLargestArray(temperatureArrayOne, temperatureArrayTwo, temperatureArrayThree); Temperature[] arrayWithLargestValues1; if(temperatureArrayOne == largest) arrayWithLargestValues1 = createArrayWithLargestValues(largest, temperatureArrayTwo, temperatureArrayThree); else if(temperatureArrayTwo == largest) arrayWithLargestValues1 = createArrayWithLargestValues(largest, temperatureArrayOne, temperatureArrayThree); else// fractionArrayThree is largest arrayWithLargestValues1 = createArrayWithLargestValues(largest, temperatureArrayOne, temperatureArrayTwo); System.out.println(" Here are the temperatures in the three arrays:"); printTemperatureArray(temperatureArrayOne); printTemperatureArray(temperatureArrayTwo); printTemperatureArray(temperatureArrayThree); System.out.println(" An array with the largest values taken from the "+ "3 arrays has " + arrayWithLargestValues1.length + " elements."); System.out.println("This solution knew the largest array of the three arrays:"); printTemperatureArray(arrayWithLargestValues1); CODE THAT FOLLOWS IS A DIFFERENT ALGORITH THAT ALSO FINDS THE LARGEST ARRAY int sizeOfLargestArray = getSizezOfLargestArray(temperatureArrayOne, temperatureArrayTwo, temperatureArrayThree); Temperature[] arrayWithLargestValues = createArrayWithLargestValues(sizeOfLargestArray, temperatureArrayOne,temperatureArrayTwo, temperatureArrayThree); System.out.println(" An array with the largest values taken from the "+ "3 arrays has " + arrayWithLargestValues.length + " elements."); System.out.println("This solution knew the largest size of the three arrays:"); printTemperatureArray(arrayWithLargestValues); }//main 

My code from the temperature class:

package ProjectTwoCSC201; import java.util.Scanner; public class Temperature { Scanner input = new Scanner(System.in); private double temperature; private char scale; public Temperature() { } public Temperature(double temperature, char scale) { set(temperature, scale); } public Temperature toKelvin() { double converted_Temp; if (scale == 'C') { converted_Temp = (temperature + 273.15); Temperature temp = new Temperature(converted_Temp, 'K'); return temp; } else if (scale == 'F') { converted_Temp = (double) ((temperature - 32) * 5.0 / 9.0 + 273.15); Temperature temp = new Temperature(converted_Temp, 'K'); return temp; } return this; } public Temperature toCelsius() { double converted_Temp; if (scale == 'K') { converted_Temp = temperature - 273.15; Temperature temp = new Temperature(converted_Temp, 'C'); return temp; } else if (scale == 'F') { converted_Temp = (double) ((temperature - 32) * 5.0 / 9.0); Temperature temp = new Temperature(converted_Temp, 'C'); return temp; } return this; } public Temperature toFahrenheit() { double converted_Temp; if (scale == 'K') { converted_Temp = (double) (temperature - 273.15) * 9.0 / 5.0 + 32; Temperature temp = new Temperature(converted_Temp, 'F'); return temp; } else if (scale == 'C') { converted_Temp = (double) (temperature * 9.0 / 5.0 + 32); Temperature temp = new Temperature(converted_Temp, 'F'); return temp; } return this; } public Temperature add(Temperature n) { Temperature converted_Scale = new Temperature(); Temperature result = new Temperature(); if (scale == 'F') { converted_Scale = n.toFahrenheit(); result.temperature = this.temperature + converted_Scale.temperature; } else if (scale == 'C') { converted_Scale = n.toCelsius(); result.temperature = this.temperature + converted_Scale.temperature; } else if (scale == 'K') { converted_Scale = n.toKelvin(); result.temperature = this.temperature + converted_Scale.temperature; } result.set(result.temperature, this.scale); return result; } public Temperature subtract(Temperature n) { Temperature converted_Scale = new Temperature(); Temperature result = new Temperature(); if (scale == 'F') { converted_Scale = n.toFahrenheit(); result.temperature = this.temperature - converted_Scale.temperature; } else if (scale == 'C') { converted_Scale = n.toCelsius(); result.temperature = this.temperature - converted_Scale.temperature; } else if (scale == 'K') { converted_Scale = n.toKelvin(); result.temperature = this.temperature - converted_Scale.temperature; } result.set(result.temperature, this.scale); return result; } public Temperature multiply(Temperature n) { Temperature converted_Scale = new Temperature(); Temperature result = new Temperature(); if (scale == 'F') { converted_Scale = n.toFahrenheit(); result.temperature = this.temperature * converted_Scale.temperature; } else if (scale == 'C') { converted_Scale = n.toCelsius(); result.temperature = this.temperature * converted_Scale.temperature; } else if (scale == 'K') { converted_Scale = n.toKelvin(); result.temperature = this.temperature * converted_Scale.temperature; } result.set(result.temperature, this.scale); return result; } public Temperature divide(double d) { Temperature result = new Temperature(); result.temperature = this.temperature / d; result.set(result.temperature, this.scale); return result; } public boolean equals(Temperature n) { if (this.scale == 'K') { n = n.toKelvin(); } else if (this.scale == 'C') { n = n.toCelsius(); } else if (this.scale == 'F') { n = n.toFahrenheit(); } return this.temperature == n.temperature && this.scale == n.scale; } public boolean greaterThan(Temperature temp) { boolean result = false; switch (this.scale) { case 'F': result = this.temperature > temp.toFahrenheit().temperature; break; case 'C': result = this.temperature > temp.toCelsius().temperature; break; case 'K': result = this.temperature > temp.toKelvin().temperature; break; } return result; } public void read() { temperature = input.nextInt(); } private void set(double temperature, char scale) { if (scale == 'F' && temperature System.out.println("'F' must be above 459.67."); System.exit(0); } if (scale == 'C' && temperature System.out.println("'C' must be above -273.15."); System.exit(0); } if (scale == 'K' && temperature System.out.println("'K' must be above 0."); System.exit(0); } this.temperature = temperature; this.scale = scale; } public String toString() { return "" + temperature + scale; } }

Instructions:

Write a program that satisfies the next 8 requirements using Temperatures. Create a class similar to the Math class. Put the next 5 static methods in it. ( These static methods could also be in the Demo class.) Use the random number generator to create 3 arrays of random sizes of 1 to 5 elements.

1. Create a static void method that has an array parameter and is called 3 times to read in Temperature values for each array.

2. Create a static method that computes and returns the average Temperature for each array and is also called 3 times.

3. Create a static method that prints the Temperatures of an array.

4. Create a static helper method that has 3 array parameters and either returns the largest array or the largest size.

5. Create a static method that returns an array of Temperatures that has the same number of elements as the largest of the three arrays. This method will have 3 array parameters and possibly an integer parameter. It determines the largest Temperature value from the three arrays at each index and creates a copy of this Temperature and stories it at that index of the new array. This array is then returned.

6. As this program is running it should generate user friendly text for input and output explaining what the program is doing. Create a set of test value Temperatures that demonstrate that your program runs correctly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!