Question
In Java please. Include comments for what your doing if possible. Do NOT import or use any classes other than ones provided in the java.lang
In Java please. Include comments for what your doing if possible. Do NOT import or use any classes other than ones provided in the java.lang package or specified in the QUESTION. You can use String, Object, any primitive Wrapper class (Integer, Double, etc.).
DO NOT EDIT THIS, THIS IS THE TEMPATURE TEMPLATE THATS BEING REFFERED TO.
public class Temperature{
/** different scale names */ public static String[] scales = {"Celsius", "Fahrenheit", "Kelvin"}; private double temperature; private String scale; private String prevScale;
/** Initializes a temperature object with given value in Celcius * * If the initial temperature is less than -273.15 then the temperature * object will be initialized with -273.15C. * * @param temp is the initial temperature in Celsius. */ public Temperature(double temp){ temperature = temp; scale = Temperature.scales[0]; prevScale = "Celsius"; }
/** Initializes a temperature object with given value using the specified scale * * If the temperature is lower than absolute zero, then set the temperature to * absolute zero (in whichever scale is specified). * * Examples: new Temperature(12.3, "K") * new Temperature(-90.2, "Celsius") * * @param temp is the initial temperature * @param scale is the scale of initial temperature and must either be * one of the Strings in the scales array, or * the first letter (capitalized) of one of those strings. */ public Temperature(double temp, String scale){ temperature = temp; this.scale = scale; prevScale = scale; }
/** getter for the scale * * The output of this getter method must always be the first letter of one * of the strings in the scales array, capitalized. * * @return the current scale of the object as a single char (the first letter, * capitalized of one of the strings from scales) */ public char getScale(){ return scale.charAt(0); }
/** getter for the temperature * * @return the temperature of the object using the current scale */ public double getTemp(){ return temperature; }
/** setter for scale * * * * @param scale is the new scale of the temperature and must either be * one of the Strings in the scales array, or * the first letter (capitalized) of one of those strings. */ public void setScale(String scale){ prevScale = this.scale; this.scale = scale; switch(getScale()){ case 'K': { if(prevScale.charAt(0) == 'C'){ temperature = temperature + 273; }else if(prevScale.charAt(0) == 'F'){ temperature = ((temperature - 32)/1.8) + 273; } break; } case 'C': { if(prevScale.charAt(0) == 'K'){ temperature = temperature - 273; }else if(prevScale.charAt(0) == 'F'){ temperature = ((temperature - 32)/1.8); } break; } case 'F': { if(prevScale.charAt(0) == 'K'){ temperature = (1.8 * (temperature - 273)) + 32; }else if(prevScale.charAt(0) == 'C'){ temperature = (1.8 * temperature) + 32; } } } prevScale = this.scale; }
/** setter for temperature * * @param temp is the new temperature (in the objects current scale) */ public void setTemp(double temp){ temperature = temp; }
/** setter for temperature * * * @param temp is the new temperature * @param scale is the scale of the new temperature. It must be * the first letter (capitalized) of one of the strings in * the scales array. */ public void setTemp(double temp, char scale){ temperature = temp; this.scale = scale+""; prevScale = scale+""; }
/** setter for temperature * * @param temp is the new temperature * @param scale is the scale of the new temperature. It must be one * of the strings in the scales array, or the first letter * (capitalized) of one of those strings. */ public void setTemp(double temp, String scale){ temperature = temp; this.scale = scale; prevScale = scale; }
public static void main(String[] args) { Temperature t = new Temperature(10.1); System.out.println(t.getScale()); System.out.println(t); t.setScale("F"); System.out.println(t); System.out.println(t.getScale()); t.setScale("K"); System.out.println(t); System.out.println(t.getScale()); }
/* ------------------------------------------------- */ /* ------------------------------------------------- */ /* do not change anything below this */ /* ------------------------------------------------- */ /* ------------------------------------------------- */
/** String representation of a temperature object */ @Override public String toString(){ return "" + this.getTemp() + this.getScale(); }
}
THIS IS THE MAX TEMP TEMPLATE THAT NEEDS TO BE EDIT BELOW HERE :
public class MaxTemp{ /** t1 and t2 are considered close enough if Math.abs(t1-t2) 2: Extreme Temperatures Complete the MaxTemp class. The class consists of a single constructor and a single getter method. The constructor takes an array of Temperature objects as input. The input will always be a reference to an array (and never null) . The getter method returns an array of doubles with exactly two doubles in it. If the object was created with one more more Temperature objects in the constructor's input array then the output consists of the maximum temperature of all Temperature objects passed to the constructor and a count of how many times that maximum was present in the array passed to the constructor (in that order). If zero Temperature objects were passed to the constructor (in the array) then the getter returns [0.0, 0.0] Note: The max temperature returned must be displayed in the Kelvin scale Note: Different Temperature objects in the array passed to the constructor may have different temperature scales set for themselves. Since the Temperature objects will store a floating point number for the temperature, you will use the provided EPSILON constant in the MaxTemp class and consider two temperatures as equal if their absolute difference is smaller than EPSILON. Therefore, if Math.abs (temp1 - temp2)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started