Write a Temperature class. the class will have three conversion methods: toCelsi
ID: 3680676 • 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 what i have so far: public class Temperature { private double temperature; private char scale; public Temperature(double temperature, char scale){ this.temperature = temperature; this.scale=scale; } public Temperature(){ } public Temperature toKelvin(){ double converted_Temp; if(scale == 'C'){ converted_Temp =(temperature+273.15); Temperature temp = new Temperature(converted_Temp, 'K'); return temp; } if(scale == 'F'){ converted_Temp=(double)((temperature-32)*5.0/9.0+273.15); Temperature temp = new Temperature(converted_Temp, 'K'); return temp; } if(temperature < 0){ System.out.println("this is k zblsolute zero 0 "); } throw new Exception("Wrong input value!!!"); } public Temperature toCelsius(){ double converted_Temp; if(scale == 'K'){ converted_Temp=temperature-273.15; Temperature temp = new Temperature(converted_Temp, 'C'); return temp; } if(scale == 'F'){ converted_Temp=(double)((temperature-32)*5.0/9.0); Temperature temp = new Temperature(converted_Temp, 'C'); return temp; } if(temperature < -273.15){ System.out.println("Cannot be below absolute zero -273.15"); throw new Exception("Wrong input value!!!"); } 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; } if(scale == 'C'){ converted_Temp=(double)(temperature*9.0/5.0 +32); Temperature temp = new Temperature(converted_Temp, 'F'); return temp; } if(temperature < -459.67){ System.out.println("this is f absolute zero -459.67"); } throw new Exception("Wrong input value!!!"); } public Temperature add(){ return this; } public Temperature subtract(){ } public Temperature multiply(){ } public Temperature divide() { } public Temperature getAverage(){ } public int getRandomArraySize(){ int getRandomArraySize = (int) (5 * Math.random()); return getRandomArraySize; } public boolean equals(Temperature temp){ Temperature tempThis = toCelsius(); Temperature tempParam = temp.toCelsius(); return tempThis.degreeValue() == tempParam.degreeValue() ? true : false; } public boolean greaterThan(Temperature temp){ Temperature tempThis = toCelsius(); Temperature tempParam = temp.toCelsius(); return tempThis.degreeValue() > tempParam.degreeValue() ? true : false; } public void read (){ System.out.println("You will be asked to fill 3 randomly sized arrays."); } public String toString(){ } public double degreeValue(){ return this.temperature; } } public static void main(String[] args){ } } ----------------------------------------------------------------------------------------------------------- AND 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); } } ----------------------------------------------------------------------------------------------------------- THIS IS HOW THE OUTPUT SHOULD LOOK LIKE: You will be asked to fill 3 randomly sized arrays. This array has 1 temperature(s). please enter a temperature in this form 45 C 300 c The values of temperature array one are 300.0C The average of temperature array one is 300.0C This array has 4 temperature(s). please enter a temperature in this form 45 C 122 f please enter a temperature in this form 45 C 0 c please enter a temperature in this form 45 C 100 c please enter a temperature in this form 45 C 50 c The values of temperature array two are 122.0F, 0.0C, 100.0C, 50.0C The average of temperature array two is 122.0F This array has 3 temperature(s). please enter a temperature in this form 45 C 212 f please enter a temperature in this form 45 C 50 c please enter a temperature in this form 45 C 32 f The values of temperature array three are 212.0F, 50.0C, 32.0F The average of temperature array three is 122.0F Here are the temperatures in the three arrays: 300.0C 122.0F, 0.0C, 100.0C, 50.0C 212.0F, 50.0C, 32.0F An array with the largest values taken from the 3 arrays has 4 elements. This solution knew the largest array of the three arrays: 300.0C, 50.0C, 100.0C, 50.0C An array with the largest values taken from the 3 arrays has 4 elements. This solution knew the largest size of the three arrays: 300.0C, 50.0C, 100.0C, 50.0CExplanation / Answer
degree *= n;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.