package eecs2030.test3;
/**
* A class that represents temperatures in degrees Celcius or degrees
* Fahrenheit.
*
* @author EECS2030 Fall 2016
*
*/
public class Temperature {
/**
* The abbreviation of Celcius.
*/
public static final String CELCIUS = "C";
/**
* The abbreviation of Fahrenheit
*/
public static final String FAHRENHEIT = "F";
/*
* YOU SHOULD ADD WHATEVER FIELDS YOU REQUIRE BELOW HERE
*/
/**
* Initializes the temperature to 0 degrees Celcius.
*/
public Temperature() {
}
/**
* Initializes the temperature by copying the numeric value and units of
* another temperature.
*
* @param other
* the temperature to copy
*/
public Temperature(Temperature other) {
}
/**
* Initializes the temperature to the given numeric value having the given
* units.
*
* @param temp
* the temperature
* @param units
* the units (Temperature.CELCIUS
or
* Temperature.FAHRENHEIT
)
* @throws IllegalArgumentException
* if units
is not one of
* Temperature.CELCIUS
or
* Temperature.FAHRENHEIT
*/
public Temperature(double temp, String units) {
}
/**
* Gets the numeric value of the temperature using the current units. For
* instance, the value of degC
is 0.0
and the
* value of degF
is 32.0
in the following example:
*
*
* Temperature t = new Temperature(0.0, Temperature.CELCIUS); * double degC = t.getTemperature(); * * Temperature u = new Temperature(32.0, Temperature.FAHRENHEIT); * double degF = u.getTemperature(); ** * @return the numeric value of the temperature using the current units */ public double getTemperature() { return 0.0; } /** * Sets the numeric value of the temperature using the current units. For * instance, the final numeric value of
t
is 15.0
* degrees Celcius in the example below:
*
* * Temperature t = new Temperature(0.0, Temperature.CELCIUS); * t.setTemperature(15.0); ** * @param temp * the numeric value of the temperature */ public final void setTemperature(double temp) { } /** * Gets the units of the temperature. * * @return
Temperature.CELCIUS
if the temperature is in
* Celcius, or Temperature.FAHRENHEIT
if the
* temperature is in Fahrenheit.
*/
public String getUnits() {
return "";
}
/**
* Set the units of the temperature. This method has the side effect that
* the numeric value of the temperature changes to reflect the change in
* units. For instance, changing the units of 0
degrees Celcius
* to Fahrenheit causes the value of degF
to be
* 32.0
(because 0C is equal to 32F):
*
* * Temperature t = new Temperature(0, Temperature.CELCIUS); * t.setUnits(Temperature.FAHRENHEIT); * double degF = t.getTemperature(); // degF is equal to 32.0 * String units = t.getUnits(); // units is equal to Temperature.FAHRENHEIT ** * @param units * the units of the temperature (
Temperature.CELCIUS
* or Temperature.FAHRENHEIT
)
* @throws IllegalArgumentException
* if units
is not one of
* Temperature.CELCIUS
or
* Temperature.FAHRENHEIT
*
*/
public final void setUnits(String units) {
}
/**
* Converts a value of degrees Fahrenheit to the equivalent value of degrees
* Celcius. The formula to convert degrees Fahrenheit to degrees Celcius is:
*
* * C = (F - 32) × (5 / 9) * *
* where F is degrees Fahrenheit and C is degrees Celcius. * * @param degF * a value of degrees Fahrenheit * @return the equivalent value in degrees Celcius */ public static double toCelcius(double degF) { return 0.0; } /** * Converts a value of degrees Celcius to the equivalent value of degrees * Fahrenheit. The formula to convert degrees Celcius to degrees Fahrenheit * is: * *
* F = C × (9 / 5) + 32 * *
* where C is degrees Celcius and F is degrees Fahrenheit. * * @param degC * a value of degrees Celcius * @return the equivalent value in degrees Fahrenheit */ public static double toFahrenheit(double degC) { return 0.0; } /** * Returns a string made up of the numeric value of the temperature followed * by its units. For example, the Strings * *
* -12.5C * 73.01234F ** *
* are returned for temperatures of -12.5
degrees Celcius and
* 73.01234
degrees Fahrenheit, respectively.
*
* @return a string representation of the temperature
*/
@Override
public String toString() {
if (this.getUnits().equals(Temperature.CELCIUS)) {
return this.getTemperature() + Temperature.CELCIUS;
} else {
return this.getTemperature() + Temperature.FAHRENHEIT;
}
}
/**
* Compares two temperatures for equality. Two temperatures are considered
* equal if they represent the same temperature expressed in degrees
* Celcius. For instance, the values of eq1
and
* eq2
are true
in the following example:
*
*
* Temperature t = new Temperature(0.0, Temperature.CELCIUS); * Temperature u = new Temperature(32.0, Temperature.FAHRENHEIT); * boolean eq1 = t.equals(u); * boolean eq2 = u.equals(t); ** *
* because 32
degrees Fahrenheit is equivalent to
* 0
degrees Celcius, and vice versa.
*/
@Override
public boolean equals(Object obj) {
// 1. you may use the eclipse generated version of equals and hashCode
// 2. you must modify the eclipse generated version of equals to
// satisfy the API stated above
// 3. you may leave or remove the eclipse generated version of hashCode;
// it won't be marked
return false;
}
}