My objective is to create a class "Temperature" that represents temperature in both Celsius and Fahrenheit. The class requires four constructors of the make up below. The part i need a hand with would be the Two accessor methods since I'm not all that familiar with it yet. I have written code but am unsure if it would work out id appreciate some insight
Four constructors: 1. one for the number of degrees 2. one for the scale 3. one for both the degrees and the scale 4. default constructor
Two accessor methods:
- one to return the temperature in degrees Celsius
- the other to return it in degrees Fahrenheit
w/ the formulas given below C = 5 ( F – 32) / 9 F = 9 * C/5 + 32
from the way i have it setup currently i BELIEVE I'm gearing towards converting from celsius to fahrenheit ONLY ... how could i make it interchangeable
please don't hate i am only a novice and might have fatal errors
package temperatureapparatus;
public class Temperature {
private float degrees;
char scale;
public static final float fahrenheitForm = ((9.0*(degrees/5.0))+32.0);
public Temperature(){
degrees = 0;
scale = 'C';
}
public Temperature(float degrees){
this.degrees = degrees;
degrees = 0;
}
public Temperature(char scale){
this.scale = scale;
scale = 'C';
}
public Temperature(float degrees, char scale){
this.degrees = degrees;
this.scale = scale;
}
public float getTempCels (float degrees, char scale){
return degrees;
}
public float getTempFehr (float degrees, char scale){
return fahrenheitForm;
}
}