In this exercise you'll be modelling a weighing machine with Kilograms as a Unit.
You have 6 tasks each of which requires you to implement one or more properties:
To cater to different demands, we allow each weighing machine to be customized with a precision (the number of digits after the decimal separator).
Implement the WeighingMachine class to have a get-only Precision property set to the constructor's precision argument:
var wm = new WeighingMachine(precision: 3);
// => wm.Precision == 3Implement the WeighingMachine.Weight property to allow the weight to be get and set:
var wm = new WeighingMachine(precision: 3);
wm.Weight = 60.5;
// => wm.Weight == 60.5Clearly, someone cannot have a negative weight.
Add validation to the WeighingMachine.Weight property to throw an ArgumentOutOfRangeException when trying to set it to a negative weight:
var wm = new WeighingMachine(precision: 3);
wm.Weight = -10; // Throws an ArgumentOutOfRangeExceptionThe tare adjustment can be any value (even negative or a value that makes the display weight negative)
Implement the WeighingMachine.TareAdjustment property to allow the tare adjustment to be set:
var wm = new WeighingMachine(precision: 3);
wm.TareAdjustment = -10.6;
// => wm.TareAdjustment == -10.6After some thorough testing, it appears that due to a manifacturing issue all weighing machines have a bias towards overestimating the weight by 5.
Change the WeighingMachine.TareAdjustment property to 5 as its default value.
var wm = new WeighingMachine(precision: 3);
// => wm.TareAdjustment == 5.0Implement the WeighingMachine.DisplayWeight property which should return a string showing the weight after tare adjustment, with the correct precision applied, and the unit added.
Note that:
display-weight = input-weight - tare-adjustment
var wm = new WeighingMachine(precision: 3);
wm.Weight = 60.567;
wm.TareAdjustment = 10;
// => wm.DisplayWeight == "50.567 kg"