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

Can I get help with this? Complete the provided Temperature class. Add any attri

ID: 3596505 • Letter: C

Question

Can I get help with this?

Complete the provided Temperature class. Add any attributes and helper methods as needed You must complete the constructors and methods in the provided class (without changing any signatures, return types, or modifiers) In this problem you will need to be able to convert temperatures between Celsius, Fahrenheit and Kelvin. For help, see https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature A temperature object holds a single temperature and displays it in one of the three scales. Once a scale has been set, it will display the temperature in that scale until changed. The default scale is Celsius if not specified Examples Temperature t - new Temperature (10.1); System.out.println (t.getScale )// outputs the char 'C System.out.println(t); t.setScale("F"); System.out.println(t); System.out.println (t.getScale )// outputs the char 'F // outputs 10.1C // outputs 50.18F Note: Repeatedly changing the scale should not "change" the value of the temperature. For example, Temperature t - new Temperature (10.1); System.out.println(t); for(int 1-0 ; i

Explanation / Answer

Here is the code for you:

public class Temperature{

/** different scale names */
public static String[] scales = {"Celsius", "Fahrenheit", "Kelvin"};
       double temperature;
       char scale;


/** 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;
       if(temperature < -273.15)
           temperature = -273.15;
       scale = 'C';  
}

  
/** Initializes a temperature object with given value using the specified scale
        * <par>
* If the temperature is lower than absolute zero, then set the temperature to
        * absolute zero (in whichever scale is specified).
        * <par>   
* 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 <code>scales</code> array, or
* the first letter (capitalized) of one of those strings.
*/
public Temperature(double temp, String scale){
       this.scale = scale.charAt(0);
       temperature = temp;
       if(temp < 0)
           temperature = 0;
}


/** getter for the scale
*
* The output of this getter method must always be the first letter of one
* of the strings in the <code>scales</code> array, capitalized.
        *   
* @return the current scale of the object as a single char (the first letter,
* capitalized of one of the strings from <code>scales</code>)
*/
public char getScale(){
return scale;
}

/** 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 <code>scales</code> array, or
* the first letter (capitalized) of one of those strings.
*/
public void setScale(String scale){
       this.scale = scale.charAt(0);
}


/** 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 <code>scales</code> array.
        */
public void setTemp(double temp, char scale){
       temperature = temp;
       this.scale = 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 <code>scales</code> array, or the first letter
* (capitalized) of one of those strings.
*/
public void setTemp(double temp, String scale){
   temperature = temp;
   this.scale = scale.charAt(0);
}


  
  
  
  

/* ------------------------------------------------- */
/* ------------------------------------------------- */
       /* do not change anything below this */
       /* ------------------------------------------------- */
/* ------------------------------------------------- */
  
  

/** String representation of a temperature object */
@Override
public String toString(){
return "" + this.getTemp() + this.getScale();
}

}

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