Question regarding using only setters and variables correctly

前端 未结 2 1249
梦毁少年i
梦毁少年i 2021-01-25 09:26

I am having an issue with my current programming assignment. I feel as though I am very close to having it correct, but something is off. I know that I have to do something diff

2条回答
  •  逝去的感伤
    2021-01-25 09:46

    Just use one specific unit to store the temperature internally, best would be Kelvin1 IMO (as it's the standard SI physical unit).

    Do the necessary calculations when setting or getting the temperature as Fahrenheit or degrees Celsius.

    Also don't use integer division to represent fractions:
    (5/9) will result as 0 integer division, it should be (5.0/9.0) to get a valid double value.
    Same with 9/5 as integer division will result as 1.


    Further issues with your code:

    1. In your function double converter(double temperature) you try to use f, which isn't in scope there
    2. In that same function you have a parameter named temperature, which shadows your member variable with the same name

    1)0K = -459,67F / 0K = -273.15°C

提交回复
热议问题