Yeah, sometimes these challenges don’t make a lot of practical sense. They can seem odd and have a lot of “wait! why?” moments.
- It is hard to come up with simple teaching examples with enough variety and that “make sense” in the real world.
- Even in the “real world” you will get jobs that don’t seem to make sense, where you are just given a list of requirements and you don’t completely get the end product, or you do and you don’t think it is the right approach. It happens.
-While creating an instance of the class, setting the temperature to whatever doesn’t matter Celsius or Fahrenheit.
No, the instructions are “The
constructor accepts a Fahrenheit temperature.”
So, the constructor will receive in F. Where it doesn’t matter is that you can store it however you want, F or C (or K or R for that matter). You chose to store it as the constructor received it, in F. That is fine, I could make an argument that it would be better to store it as C since you will need to access it more that way, but it works either way.
With get function, convert the value to Celsius, even if it is already in Celsius, and return this value.
You stored it in F so it needs to be converted. If you had converted and stored in C in the constructor, then you wouldn’t need to convert.
With the set function, convert the value that we are getting from arguments to Fahrenheit and set it. Doesn’t matter if its already in Fahrenheit.
No, it does matter. The instructions are: “In the class, create a
getter to obtain the temperature in Celsius and a
setter to set the temperature in Celsius.”
You could have written it differently, where everything is C (or whatever). You could have written it to allow either F or C (which would have been more complicated, but doable.
But as the problem is given to you, the constructor accepts F and the getter and setter deal in C. Does that make sense in the “real world”? Maybe not. It’s a little odd. Is it the type of “strange requirements” you may encounter on the job? Yup.
If I were designing this module from scratch, it certainly wouldn’t work this way. But I didn’t design it. Sometimes we have to understand and build to other people’s specifications.
As to the description, I think it’s decent. Trust me, on the job, I’ve gotten much, much worse specs, with contradictions and gaping holes.