I'm new to Java, so I'm sure this is an easy question (my head is spinning from studying all day long). Here's the code I'm studying and can't remember/figure out what this line of code is doing:
public Temperature(String type, double degrees) {
if (type.equalsIgnoreCase("C"))
Is this considered a constructor? What are the two parameters "String type, double degrees" doing? tia.
Here's the code from the top down:
public class Temperature {
private double degreesFahrenheit; // Fahrenheit temperature
private double degreesCelsius; // Celsius temperature
private double degreesKelvin; // Kelvin temperature
/** * This constructor for Temperature sets the temperature
* values to the value from degrees, based on the type *
* @param type temperature scale to use
* @param degrees degrees Fahrenheit
*/
public Temperature(String type, double degrees) {
if (type.equalsIgnoreCase("C"))
setDegreesCelsius(degrees);
else if (type.equalsIgnoreCase("F")) setDegreesFahrenheit(degrees);
else if (type.equalsIgnoreCase("K")) setDegreesKelvin(degrees);
...
See Question&Answers more detail:os