solution

Inspect the Temperature class provided – which stores two attributes: degrees and unit. For example – I could create a new Temperature object with degrees set to 32 and unit set to ‘F’ to represent a temperature of 32 degrees Fahrenheit (F).

Your task is to write a method named convert() within the Temperature class that accepts no arguments/parameters and does not return a value (void). This method should not print anything to the console. Pay close attention to the instructions above as setting up your method definition incorrectly will cause the autograder to fail.

The convert method should update the degrees attribute to be the converted equivalent value (Celsius to Fahrenheit or Fahrenheit to Celsius) based on the formula below and the current value of unit – ex: if unit is set to ‘C’, use the formula to convert from Celsius to Fahrenheit. The method should also update the unit attribute to the opposite value — so (32, F) should be converted to (0, C).

If your unit attribute is not set to ‘C’ or ‘F’ – no conversion should be made (do not update degrees or unit attributes). Any value for degrees is considered valid.

Below are the formulas for the conversions:

Convert Celsius (C) to Fahrenheit (F): F = (C * 9/5) + 32

Convert Fahrenheit (F) to Celsius (C): F -> C: C = (F- 32) * 5/9

public class Tester
{
public static void main(String[] args) {
//This file is not graded. You can test your code here

}
}

public class Temperature {

private int degrees; // temperature in degrees: Ex: 32
private char unit; // either ‘C’ or ‘F’ (for Celsius or Farenheit)
public Temperature(int degrees, char unit)
{
this.degrees = degrees;
this.unit = unit;
}
public int getDegrees() {
return degrees;
}
public void setDegrees(int degrees) {
this.degrees = degrees;
}
public char getUnit() {
return unit;
}
public void setUnit(char unit) {
this.unit = unit;
}
//Do not modify above code. Insert method here.
//write a method named convert that updates your two attributes.

}

 
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp