Yes, we do rock, but I am not totally happy about your WeightCalculator class, I am afraid.
You have fields which you set to 0 and
null. I think you ought to be initialising those in a constructor, so you never have those 0 and
null values running around. 0s are’t too bad, but a
null can escape and cause an Exception a long way away from where the
null was created. You would call it as
new WeightCalculator("Elephant", 5000). That allows you to miss out the two setXXX calls, because those values are already set. By only giving the WeightCalculator class the one constructor which takse the two arguments, you can make sure those fields are always initialised.
You can see an example of a constructor
here, but if it has the bit about speed cadence and gear in, that isn’t quite mathematically sound because speed = gear × cadence × 60 × π ÷ 63360, so cadence = 30 and speed = 0 don’t quite add up
It also says there that you don’t have to provide a constructor, but that is hazardous. If you look in other documentation, eg this
“How to Write Documentation Comments” page, they say
you should always write a constructor. Agree. It is a good policy always to write a constructor for every class, because you can then control instantiation of that class, ensuring you always get the correct values for your fields.
If you ever have a class you wish to prevent from being instantiated, look here, but it isn’t easy to read.